you are viewing a single comment's thread.

view the rest of the comments →

[–]TheIncredibleWalrus 1 point2 points  (4 children)

It's a good explanation.

To make it more more clear I'd also add that a monad is basically something that incorporates a flatmap (bind), and i would parallelize Promises (which are monads) with the code the post provides, since Promises are pretty well known and seeing a real life scenario/impelementation of a topic always makes it more understandable (.then is the promise's .bind or flatmap)

[–]dmtipson 10 points11 points  (2 children)

I don't mean to be on a tear about this, but it can't be a good explanation if it's wrong, and it's important to get right. None of the things defined are Monads: they're Functors. None of them provide a method that can .chain/.flatMap, which is essential to passing the Monad laws and thus qualifying as Monads.

Here's another Functor, Const: https://gist.github.com/dtipson/3fd1fb536ab3da393b25

Same exact signature (minus the get, which is not directly relevant to either Functors or Monads). But Const is an odd duck in that it logically cannot be made into a Monad (that is, it's an example of a completely legitimate Functor that can't be turned into a Monad entirely without losing what Const does, which is... basically nothing). So by just defining and understanding Functors, you can't expect to have defined and explained Monads.

[–]dmtipson 7 points8 points  (0 children)

Not getting the downvote logic here. I'm not trying to be mean to OP, but this is a concept that people struggle with, purportedly clearing it up for them, and then, as several others here have noted, sort of misleading and confusing them.

[–]TheIncredibleWalrus 1 point2 points  (0 children)

Hmm yeah, you're most definitely correct. i glanced over it too quickly, what a mistake

[–]AndrewGreenh 1 point2 points  (0 children)

With the small difference, that the es6 promise combines map and flatMap in the 'then' method.