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
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?
Hey everyone! :)
Is there a class that abstracts over the concept of "consing" an
a
to anf a
? Something that captures appending a char to a string or an element to a list or an array? Essentially a function of typeConsable 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?
Awesome, that's exactly it! Thanks for the help, I managed to make the function a lot more ergonomic this way :)