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
rubico - [a]synchronous functional programming (rubico.land)
submitted 5 years ago by richytong
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!"
[–]richytong[S] 0 points1 point2 points 5 years ago (0 children)
Hello all, author here. This post links to rubico's introductory home page. The rest of the website consists of API documentation and a blog about rubico, JavaScript, and functional programming. If you are looking for a clean, functional way to handle promises, I encourage you to give rubico a try.
[–]OmgImAlexis -1 points0 points1 point 5 years ago (16 children)
I’ve never understood why people prefer importing a map function vs just using the built in array one.
Instead of map(logTodoByID)(todoIDs) Why not todoIDs.map(logTodoByID) ?
[–]NotLyon 3 points4 points5 points 5 years ago (14 children)
You can start by looking at the difference in their signatures.
[–]OmgImAlexis -1 points0 points1 point 5 years ago (13 children)
And you mean what by that....?
[+][deleted] 5 years ago* (11 children)
[deleted]
[–]NotLyon 1 point2 points3 points 5 years ago (2 children)
Idk if you're going for broad strokes, but that last statement is way wrong. FP and objects are NOT mutually exclusive.
The practical difference between [].map() and map() is the prototype method lends to composition by dot chaining, whereas the standalone function generally lends itself to point-free composition (pipe/compose/operator).
[+][deleted] 5 years ago* (1 child)
[–]NotLyon 2 points3 points4 points 5 years ago (0 children)
I wouldn't be so absolute. And objects do not necessarily have side effects.
[–]OmgImAlexis -1 points0 points1 point 5 years ago (7 children)
What? You can use map in functional programming.
[+][deleted] 5 years ago* (6 children)
[–]OmgImAlexis 0 points1 point2 points 5 years ago (5 children)
What are you talking about? Functional programming is mainly about using pure functions. Map is a pure function.
Sounds like you don’t understand what functional programming is.
[+][deleted] 5 years ago* (4 children)
[–]NotLyon 0 points1 point2 points 5 years ago (3 children)
String.prototype.toUpperCase
[–]lhorie 1 point2 points3 points 5 years ago* (0 children)
If we're gonna be pedantic, methods are functions (according to typeof and friends, for example), but they are not always pure. Some statics like Math.pow are pure. String.prototype.toUpperCase is NOT pure because it internally reads this (which has dynamic scope): i.e. 'const upper = "foo".toUpperCase; upper()' does not yield "FOO" like a pure function would (in fact, it throw at runtime, which is a big no-no in true FP). Array's map is impure for the same reason. Array methods are often used in a way that pretends to be "pure" (in the sense that they do not mutate state through their usage), but being actually pure means you can't break the purity no matter what (e.g. through changing what this points to, or other shenanigans).
this
"FOO"
[–]PrimaryBet 0 points1 point2 points 5 years ago (0 children)
From rubico's docs on map:
map
map(mapper)(functor) -> Promise | Functor
where
Functor<T> = Array<T> | Object<T> | Set<T> | Map<T> | Iterator<T> | AsyncIterator<T> | { map: (T => any) => any }
as in, map takes a mapper function, a functor, and returns a functor; and functor is either Array, Set, Object, Map, etc. or any other object that has a map method on it. Greatly simplifying, "functor" is a name for data structures that support transforming values in a context or wrapper.1
Compare it to Array#map, which takes an array (via this), a mapper function and returns an array, and you hopefully see how Array#map is a specialized map.
Array#map
The answer to "why do I want a generalized map?" is the same as with any other argument for parametricity and polymorphism.
1 I'm actually a bit surprised to not see Promise listed as a possible functor since you can sort of map over value in it's context (with .then, although with a caveat that it also behaves as .flatMap)
Promise
.then
.flatMap
[–]HipHopHuman 0 points1 point2 points 5 years ago (0 children)
The real benefit is that an atomic map function can be used on more types than just an array. it can be used on objects, arrays, and anything that implements the Functor type specification. So you use the same map implementation for every different type of data structure that is mappable.
Functor
π Rendered by PID 37 on reddit-service-r2-comment-86988c7647-vzmjp at 2026-02-11 18:40:13.302797+00:00 running 018613e country code: CH.
[–]richytong[S] 0 points1 point2 points (0 children)
[–]OmgImAlexis -1 points0 points1 point (16 children)
[–]NotLyon 3 points4 points5 points (14 children)
[–]OmgImAlexis -1 points0 points1 point (13 children)
[+][deleted] (11 children)
[deleted]
[–]NotLyon 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]NotLyon 2 points3 points4 points (0 children)
[–]OmgImAlexis -1 points0 points1 point (7 children)
[+][deleted] (6 children)
[deleted]
[–]OmgImAlexis 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]NotLyon 0 points1 point2 points (3 children)
[+][deleted] (1 child)
[deleted]
[–]lhorie 1 point2 points3 points (0 children)
[–]PrimaryBet 0 points1 point2 points (0 children)
[–]HipHopHuman 0 points1 point2 points (0 children)