Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
Hey everyone! :)
Is there a class that abstracts over the concept of "consing" an a to an f a? Something that captures appending a char to a string or an element to a list or an array? Essentially a function of type Consable f => a -> f a -> f a
Consable f => a -> f a -> f a
I'm going through the Functional Programming Made Easier book by Charles Scalfani and the way he generalizes over this is by creating wrapper functions that pass in their specific "cons-like" function. In PureScript it happens to be (:) for Array, (:) for string, cons for list, etc. It feels very clunky to do so but I couldn't find a typeclass for it anywhere. Is there maybe a reason for it I'm failing to realize?
Compose Semigroup and Applicative?
Prelude> :t (<>) . pure
(<>) . pure :: (Semigroup (f a), Applicative f) => a -> f a -> f a
Awesome, that's exactly it! Thanks for the help, I managed to make the function a lot more ergonomic this way :)