#flat-map Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Java Optional Chains — flatMap, filter
`flatMap` lets you chain Optional-returning methods without nested `if`. `filter` short-circuits to empty if the predicate fails. The functional equivalent of safe-navigation `?.`.
Rust flat_map and Iterator::flatten
`flat_map(f)` is `map(f).flatten()` — map each item to an iterator, then concatenate. Indispensable for working with nested structures.
Kotlin flatMap and Flattening
`flatMap` maps each item to a collection, then concatenates. Use it when "for each X, produce N Y's, collect all Y's". `flatten()` is the no-mapping version.
Java flatMap — Flatten Nested Streams
Map each element to a Stream, then concatenate all of them into one. Used everywhere from "all words from a list of sentences" to "all permissions from a list of roles".