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

pluck

Extracts the value under one key from every map in an iterable — a one-liner for the common "get me just this field" query.

Iterable<V?> pluck<K, V>(K key, Iterable<Map<K, V>> iterable) FxAsyncIterable<V?> pluckAsync<K, V>(K key, FxAsyncIterable<Map<K, V>> iterable)

Lecture

pluck is a tiny, named specialization of map — literally map((a) => a[key], iterable) under the hood. It exists because "grab one field from a list of records" is common enough to deserve its own name, and reads better at a call site than a one-off lambda.

Notice the return type is Iterable<V?>, not Iterable<V>: a Map lookup can never guarantee the key is present, so a missing key becomes null in the result rather than throwing. If you need to drop those nulls afterward, chain into compact.

There is no chain method for pluck on Fx/FxAsync — only the data-first top-level function exists. Call it directly on your source, or wrap the result with fx(...)/fxAsync(...) to keep chaining afterward.

Demo 1 · Basics & missing keys

Demo 2 · Async, with concurrency

pluckAsync is built directly on mapAsync, so fetch the records concurrently first, then pluck what you need:

Try it yourself

Exercise: use pluck to get a list of just the product titles.

Related: map — the general form pluck specializes · compact — drop the nulls pluck can produce · prop — pluck's single-map cousin · filter — keep matching elements