Эта страница ещё не переведена, поэтому показана на английском. Помогите с переводом

map

Returns a lazy iterable of values produced by running each element through a function.

Iterable<B> map<A, B>(B Function(A a) f, Iterable<A> iterable) FxAsyncIterable<B> mapAsync<A, B>(FutureOr<B> Function(A a) f, FxAsyncIterable<A> iterable) Fx<R> Fx.map<R>(R Function(T a) f) // chain FxAsync<R> FxAsync.map<R>(FutureOr<R> Function(T a) f)

Lecture

map is the most fundamental transformer: it applies a function to every element. In FxDart it is lazy — calling map does no work at all. The function runs only when a terminal operator (toList, each, reduce, …) pulls values through the pipeline. That means you can map over an enormous — even infinite — sequence, as long as you only pull what you need.

It comes in data-first form (map(f, iterable)) and as a chain method (fx(iterable).map(f)). Both return the same lazy result.

Demo 1 · Basics & laziness

Note how the mapping function only runs for the 3 values that take(3) pulls — out of a million:

Demo 2 · Async, with concurrency

mapAsync (or .toAsync().map(...)) accepts an async function. On its own it awaits each element in order; add concurrent(n) and the upstream evaluates n elements at a time — results still arrive in order:

Try it yourself

Exercise: use map to turn this list of maps into a list of formatted name strings like "KIM (32)".

Related: mapEffect — same as map, signals side effects · flatMap — map + flatten · peek — observe without transforming · concurrent — parallel evaluation