JSMonk / sweet-monads

The library which provides useful monads, interfaces, and lazy iterators.
MIT License
343 stars 22 forks source link

Support for `cata` #52

Closed wookieb closed 1 year ago

wookieb commented 1 year ago

I would really like to see suport for catamorphism

Similar to: https://github.com/monet/monet.js/blob/master/docs/MAYBE.md#cata

JSMonk commented 1 year ago

Hey @wookieb. Sounds nice, I like it. The only thing, the name is not eloquent. What do you think, what will be a better name for the function?

wookieb commented 1 year ago

I really have no better idea for a name... Any suggestions?

JSMonk commented 1 year ago

mapBoth?

wookieb commented 1 year ago

https://www.npmjs.com/package/node-either-monad - uses fold https://github.com/sniptt-official/monads - uses match - which is also good https://folktalegithubio.readthedocs.io/en/latest/api/data/either/Either.html#cata - uses cata https://itnext.io/either-monad-a-functional-approach-to-error-handling-in-js-ffdc2917ab2 - uses matchWith https://gcanti.github.io/fp-ts/modules/Either.ts.html#mapping - uses fold

I believe let's go with fold since match accepts object and we can introduce it later.

wookieb commented 1 year ago

@JSMonk Do you agree to go with fold ?

JSMonk commented 1 year ago

I would like to name it match with one a few variants

pawlufelice commented 1 year ago

I prefer fold personally as it's descriptive of doing away with the monad.

JSMonk commented 1 year ago

I agree with you, but, and I'm open to discussion. But, my point of view is that the fold would confuse people from other non-pure-functional languages, because the fold method commonly is a collection method to make folding of the collection to some value.

wookieb commented 1 year ago

Yes but this is fold in collections, not in a Maybe monad. Therefore I would go with it.

wookieb commented 1 year ago

I've encountered some issue with commiting and lint-staged failing with some error about yarn.lock. Had to switch to yarn 1.22.1 but that created some files not available in the repository before. I did not committed them.

@JSMonk can You please fix configuration of yarn package or provide details regard contribution?

Voltra commented 1 year ago

That's just bifoldMap from Bifoldable: https://hackage.haskell.org/package/base-4.18.0.0/docs/Prelude.html#v:bifoldMap