#flatMap
I feel like JavaScript's arr.flatMap() should have been named:

arr.mapFlat()

because it maps first, then flats.

I often *do* want to flat first then map, and accidentally reach for flatMap() 🤨
December 11, 2025 at 8:08 PM
Advent of code day 2 in Lean
December 3, 2025 at 5:04 AM
or a flatMap ;)
December 5, 2024 at 7:45 AM
return customers()
.map(Customer::id)
.flatMap(service::thing
.collectList()
.flatMap(list -> Mono.zi(Mono.just(list, otherThing(format(format, join(delimiter, list.strea().map(Thing::id).toList())).map(tuple ...)

What the fuck is wrong with you?

Why would you nest so many functions?
November 14, 2024 at 4:48 AM
Uma coisa besta que me irrita no java hoje em dia: o flatMap só funcionar para streams (e não para Optional).
Você pode transformar com o toStream, mas isso significa que não dá pra usar method reference.
Tô quase retornando Stream ao invés de Optional em alguns métodos.
October 22, 2025 at 3:22 AM
flatMap pode ser implementado com recursão apenas
Map to double é só uma funcão 1:1 aplicada em uma lista. Pode ser feita como um reduce (ou recursão, obviamente)
November 7, 2024 at 3:30 AM
I wrote some code and can't tell if it's wonderful or awful or both.
September 11, 2024 at 8:38 PM
Can it be expressed as easily as `flatMap` for monads? I have a vague impression that yes, but can you come up with some details?
February 15, 2025 at 6:56 PM
I used flatMap for the first time yesterday, and I’ve been riding that high ever since.
November 2, 2024 at 2:45 PM
Pq filter filtra e map mapeia =P

Poderia tentar fazer ambos ao mesmo tempo? Sim, mas seria um abuso de como fazer esse mapeamento via flatmap da vida, ou um reduce próprio o que na minha visão perde o sentido.
April 2, 2025 at 7:12 PM
(>>=) is a monadic let binding so unless you do, flatMap just not the right intuition
March 30, 2025 at 11:51 AM
I thought compactMap was bad (though worth it to disambiguate flatMap). But then the JavaScript community was like, let's one the fuck up that idea.

https://github.com/tc39/proposal-flatMap/pull/56#issuecomment-371224179
rename flatten to smoosh by michaelficarra · Pull Request...
As reported in Bugzilla bug 1443630, 8+year old versions ...
github.com
November 22, 2024 at 12:20 PM
Array.prototype.reduce gets quite close: The callback's 3rd arg is the index. Return the accumulator and the current value spreaded to flatten.

Eg.

[[1], [2,2], [3,3,3]].reduce((acc, curr, idx) => idx > 1 ? [...acc, ...curr] : acc, [])

I'd argue chaining filter and flatMap is usually clearer tho
December 28, 2024 at 10:39 PM
you could forget map, flatMap, filter and use only fold/reduce. but should you?
May 8, 2025 at 1:06 PM
just realized flatMap is the same as foo.map().flat() and not foo.flat().map() and now my day is ruined
May 15, 2025 at 12:50 PM
Sneak peak at the best mouse 🐁 brain 🧠 networks yet. A whole-cortex flatmap connectivity in factored form, methods and data to be released soon 🧐
November 2, 2024 at 8:37 PM
New major release for #php innmind/black-box:
- Set is now a final class
- adds Set::flatMap() to randomly declare new Sets
- adds PHPUnit 12 support

github.com/Innmind/Blac...
Releases · Innmind/BlackBox
Contribute to Innmind/BlackBox development by creating an account on GitHub.
github.com
March 19, 2025 at 7:28 PM
“JavaScript arrays are getting two new methods: flat() and flatMap(). They return a new array with all sub-array elements smooshed into it.”

🤣🤣🤣 I still wish it was Array.smoosh() https://twitter.com/ChromiumDev/status/1037022478927912961
November 18, 2024 at 11:36 PM
flatMap is fundamentally a different operation, it just happens to line up with the implementation of bind for non-determinism because flatMapping the continuation over the rhs happens to produce the result you're after
March 30, 2025 at 2:06 PM
Rule number 2 - never trust flatMap()
first rule of #ReactiveProgramming - when in doubt - flatMap()
November 22, 2024 at 11:39 PM
Isso parece estar menos ligado ao flatmap e mais ligado ao fato dele ter sido chamado em um stream sequencial
April 4, 2025 at 10:07 PM
Boa, vou continuar minha luta aqui pra aprender certinho. Tava apanhando um pouco pra uns flatMap, minha cabeça ainda tá pensando muito imperativo kk
September 8, 2024 at 1:35 AM
Pequenas coisas que me deixam triste, o flatMap do java não lidar com optional. Ter que dar um .stream() tira toda a beleza do que poderia ser referência ao método.
November 29, 2024 at 1:40 PM
I have to keep reminding myself that flatMap() does map() then flat(), not the other way around.
November 12, 2024 at 3:15 PM
Programming language agnostic feature request: a compiler error that included the hint, “did you mean flatMap instead of map?”

It would have me days of my life if I added up all the time I’ve spend arriving at that conclusion.
June 22, 2023 at 9:39 PM