konsumlamm / rrb-vector

An implementation of a Relaxed Radix Balanced Vector in Haskell.
BSD 3-Clause "New" or "Revised" License
20 stars 5 forks source link

Witherable instances #24

Open Benjamin-McRae-Tracsis opened 1 week ago

Benjamin-McRae-Tracsis commented 1 week ago

I think it would be good to add an efficient Filterable and Witherable instance for vectors.

konsumlamm commented 1 week ago

Originally, the reason I didn't include filter/mapMaybe was that I thought the best implementation would depend on the predicate. However, upon benchmarking, it seems that using Data.List.filter, i.e.

filter f = fromList . Data.List.filter f . toList

is the fastest implementation overall (at least the fastest I can think of). I'm not sure about adding functions that just use list functions, since users can easily do that themselves and even combine multiple transformations without converting to vectors in between (though tbf, zip and zipWith are also implemented this way).

I'd also like to avoid a dependency on witherable, to keep the dependency footprint low.