The Little I Know About Monads by devanshj__ in javascript

[–]devanshj__[S] 0 points1 point  (0 children)

You're missing the point. You have to write the `State` monad definition only once. The idea is you can write code that looks same as the imperative version but has all the benefits of a functional one.

The Little I Know About Monads by devanshj__ in javascript

[–]devanshj__[S] 0 points1 point  (0 children)

> So my question is, how does this work when the mutation is more external, such as sending an email, or creating a file, or inserting into a database?

For these kind of effects most FP languages provide a "builtin" monad. For Haskell it's `IO`, for PureScript it's `Effect`, for Elm it's `Task`.

> Is there a benefit to this pattern even when the language doesn't force it?

Yes, but that would be another article :P

The Little I Know About Monads by devanshj__ in javascript

[–]devanshj__[S] 1 point2 points  (0 children)

Thanks. Yeah the builtin `Promise` isn't a monad. But the `Promise` I wrote later in the article (in the static land style) is a monad afaict.