From: Peter J. <pe...@jo...> - 2005-11-24 16:15:43
|
Richard Jones wrote: >Amit Dubey wrote: >> Array.find >> >> Will this return the element or an index? > > I'm not sure which is better? I think probably having Array.find be > exactly like List.find, ie. returning an element, and having an > additional Array.find_index to return the index would be the best > idea. What do people think? The principle of least surprise suggests that identically-named functions should have identical behaviours, so I agree with this. >> Array.filter >> Array.find_all >> Array.partition >> >> Would these return lists or arrays? > > I think it's better to return arrays, but what do people think about > that? Again, since List.filter returns a list and Enum.filter returns an enum, it seems logical that Array.filter should return an array. The other behaviour can be derived trivially, and hopefully not too inefficiently, by doing the filtering on an intermediate enum: let filter_to_list f a = List.of_enum (Enum.filter f (Array.enum a)) Incidentally, I notice that DynArray lacks most of these functions too, including sort. Would it be worth adding them there, to give all the common linear containers equivalent interfaces? |