composewell / streamly

High performance, concurrent functional programming abstractions
https://streamly.composewell.com
Other
859 stars 65 forks source link

Change the signatures of demux and friends #2724

Open harendra-kumar opened 7 months ago

harendra-kumar commented 7 months ago

From:

demux :: (Monad m, Ord k) => (a -> k) -> (a -> m (Fold m a b)) -> Fold m a (m (Map k b), Maybe (k, b)) 

To:

demux :: (Monad m, Ord k) => (k -> m (Fold m a b)) -> Fold m (k, a) (m (Map k b), Maybe (k, b)) 
harendra-kumar commented 2 months ago

The minimal change required is to generate the fold using the key k rather than the value a for safety:

demux :: (Monad m, Ord k) => (a -> k) -> (k -> m (Fold m a b)) -> Fold m a (m (Map k b), Maybe (k, b))

For key-value inputs we can have different versions of this named demuxKv etc.