sanctuary
sanctuary copied to clipboard
Add `asum`
// :: (Foldable f, Plus g) => TypeRep g -> f (g a) -> g a
const asum = A => S.reduce(S.alt)(S.zero(A))
I should note here that Flutures might be one common Alt that we wish to use this function with, however after some discussion in the Fluture chatroom it was concluded that it doesn't make much sense for the non-concurrent Fluture to implement the full Plus; instead it's only going to implement Alt.
To work with such instances, it might be better for asum to explicitly accept a zero case and weaken the constraint to:
// :: (Foldable f, Alt g) => f (g a) -> g a -> g a