On 11/24/05, Richard W. M. Jones <rich@merjis.com> wrote:
> Actually, I agree it makes complete sense for partition.  As I think about
> it, I think filter and find_all should be different.  find_all should return
> a list, and filter should return an array.  And possibly, filter should be
> defined in terms of find_all.

Perhaps you can share your thinking on this :-)


I think the principle of least surprise is going to be that
Array.filter should return an array - this is surely what users would

I agree: filter implies you're given a container,  then you "filter" away some elements, still left with the same type of container.

Find_all suggests you're just looking for all matching elements.  It doesn't suggest any particular data structure.  So, a list is as good as anything.

The problem will be in the implementation which may require
two passes -- it could be solved better if there was a truncation
primitive for arrays.

As I suggested above, one way to implement filter is just:

let filter x y = of_list (find_all x y)

There are a number of other implementations, it might make sense to write a benchmark to decide which is faster.  One worry with a two-pass approach, though, is it might be incompatible with find/inclusion functions that contain state (i.e. the state might get confused on the 2nd call).