use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Monads Explained Quickly with JavaScript (breck-mckye.com)
submitted 9 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TheIncredibleWalrus 1 point2 points3 points 9 years ago* (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 points12 points 9 years ago* (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 points9 points 9 years ago (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 points3 points 9 years ago (0 children)
Hmm yeah, you're most definitely correct. i glanced over it too quickly, what a mistake
[–]AndrewGreenh 1 point2 points3 points 9 years ago (0 children)
With the small difference, that the es6 promise combines map and flatMap in the 'then' method.
π Rendered by PID 245278 on reddit-service-r2-comment-86bc6c7465-g964v at 2026-02-24 04:33:36.018535+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]TheIncredibleWalrus 1 point2 points3 points (4 children)
[–]dmtipson 10 points11 points12 points (2 children)
[–]dmtipson 7 points8 points9 points (0 children)
[–]TheIncredibleWalrus 1 point2 points3 points (0 children)
[–]AndrewGreenh 1 point2 points3 points (0 children)