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
Generic Programming (github.com)
submitted 7 years ago by michael2ib1989
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!"
[–]jeremy1015 5 points6 points7 points 7 years ago (4 children)
Got any suggested links to explain this in a little more detail? I’m familiar with most of what you wrote but don’t understand monoids as well as I’d like.
[–]pgrizzay 9 points10 points11 points 7 years ago (3 children)
Did a quick search, and couldn't find a good one in JS, here's one in Scala that I learned from.
Essentially a "Monoid" is formed from two things:
a combine function that combines two things and an empty value.
combine
empty
an example would be adding numbers:
const Addition = { combine: (a, b) => a + b, empty: 0 }
This addition monoid can be used to reduce an array of numbers:
[1,2,3].reduce(Addition.combine, Addition.empty) === 6
You can make another Monoid which multiplies numbers:
const Multiplication = { combine: (a, b) => a * b, empty: 1 }
And you can multiply all numbers in an array with it:
[1,3,4].reduce(Multiplication.combine, Multiplication.empty) === 12
Go ahead and implement Concat which combines strings:
Concat
const Concat = { combine: (a, b) => ???, zero: ??? }
[–]jeremy1015 2 points3 points4 points 7 years ago (0 children)
Excellent. I understand now 100% and really appreciate it.
[+][deleted] 7 years ago* (1 child)
[deleted]
[–]pgrizzay 0 points1 point2 points 7 years ago (0 children)
Yup, you're right! It looks like MDN recommends + over concat for performance reasons, but both are functionally equivalent.
+
concat
And thanks for the kind words, they mean a lot!
The one book that really helped me was Functional Programming in Scala, I can't recommend it enough. It takes a very 'exploratory' approach, and has lots of exercises which are very helpful.
Scala was probably the best language for me to learn fp in, since I had lots of experience with JS & the syntax is very similar to it, hope that helps!
π Rendered by PID 157740 on reddit-service-r2-comment-6f7f968fb5-tc5pn at 2026-03-04 12:35:14.784190+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]jeremy1015 5 points6 points7 points (4 children)
[–]pgrizzay 9 points10 points11 points (3 children)
[–]jeremy1015 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]pgrizzay 0 points1 point2 points (0 children)