本页尚未翻译,因此以英文显示。 参与翻译

fxPluck

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?> fxPluck<K, V>(K key, Iterable<Map<K, V>> iterable) FxAsyncIterable<V?> fxPluckAsync<K, V>(K key, FxAsyncIterable<Map<K, V>> iterable)

Lecture

fxPluck is a tiny, named specialization of map — literally fxMap((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 fxCompact.

There is no chain method for fxPluck 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

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

Try it yourself

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

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