Set.partition
Opened this issue · 3 comments
First of all, thanks for this wonderful library!
I had a need to do a partition on a Set and noticed that function is not provided. I had to convert the Set to an Array to use Array.partition and then convert it back to a Set.
Is there a reason why Set.partition isn’t provided? I don’t see any immediate contradiction in its functionality. If there’s no particular reason, would you be open to a PR?
The reason is most likely that we haven't yet gotten around to adding it. Just to be clear, is this the function you're after?
partition :: forall a. Ord a => (a -> Boolean) -> Set a -> { yes :: Set a, no :: Set a }We should add partition to purescript-maps first though; that way, the implementation can take advantage of having access to the internal Map representation which could make it a bit faster. Even if we do it the naive way at first, we can optimise it in maps later, and then the Set version automatically benefits.
@hdgarrood Yes, that’s the function. Thanks for the pointer to purescript-maps. I am not sure yet when I’ll have time, but how about I take a stab at it and submit a PR?
Yep, sounds good! I guess in maps we would probably want to provide both partition :: forall k v. Ord k => (v -> Boolean) -> Map k v -> { yes :: Map k v, no :: Map k v } and also partitionWithKey :: forall k v. Ord k => (k -> v -> Boolean) -> Map k v -> { yes :: Map k v, no :: Map k v }, to line up with the existing functions filter / filterWithKey.