I am missing the pointfree chain function in this library.
I have several functions of signature Functor f => a -> f a, which I would like to compose using pipe.
I have written the following conversion to pointfree of chain to allow this.
// Functor f => (a -> f a) -> f a -> f a
const chain = func => x => x.chain(func);
Now I can write
// Functor f => a -> f a
const composed = pipe([func1, chain(func2), chain(func3)]);
Maybe there is a different intended way of doing this with this library? If not, I think the simple chain function would be a good addition.
I agree that this is a great idea! Ramda provides R.chain, and I'd love Sanctuary to provide S.chain.
I don't think the implementation is quite as simple as func => x => x.chain(func), since it would be nice to provide an implementation for Array (as Ramda does).
@svozza has been working on a map implementation in #142. We've encountered a few problems, but once we've resolved them all it should be fairly easy to add chain.
I believe the correct signature is:
chain :: Chain m => (a -> m b) -> m a -> m b
Oh yes you're right of course about the signature.
The implementation I suggested works for Chains in Sanctuary; and as for Arrays, the Ramda function is available. However, I read in #142 that you aim to lose that dependency in the future, in which case I agree chain should address Arrays as well.
To clarify the relationship between Ramda and Sanctuary, Sanctuary is currently complementary to Ramda. At some point, though, Sanctuary will be an alternative to Ramda, providing much of the same functionality but with a different approach to handling type errors.
Most helpful comment
To clarify the relationship between Ramda and Sanctuary, Sanctuary is currently complementary to Ramda. At some point, though, Sanctuary will be an alternative to Ramda, providing much of the same functionality but with a different approach to handling type errors.