このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

fxPipe1

Applies one function to a value, awaiting it first if the value is a Future.

FutureOr<R> fxPipe1<A, R>(FutureOr<A> a, FutureOr<R> Function(A a) f)

Lecture

fxPipe1 is the single-step form of pipe: apply f to a, but if a is a Future, await it first. If a is a plain value, f runs immediately and fxPipe1 returns whatever f returns — synchronously, with no Future wrapper at all.

The point is that f itself never has to know or care whether the value it receives came from sync or async work upstream — fxPipe1 normalizes that for you. This is handy when you're composing a value that's sometimes a Future (say, the result of an earlier async step) and you want the next step to look identical either way.

Because it only handles one step, you can nest fxPipe1 calls to compose a short chain, or reach for the full pipe (a List<Function>) when there are more than one or two steps.

Demo 1 · A plain (non-Future) value

With no Future involved, fxPipe1 just calls f(a) directly and returns a plain value:

Demo 2 · Awaiting a Future first

When a is a Future, fxPipe1 awaits it before calling f — chain a few of these together to compose async steps one at a time:

Try it yourself

Exercise: use fxPipe1 to turn a delayed name into a greeting.

Related: pipe — multi-step pipeline, the same idea for a list of steps · fx — the typed chain alternative · fxDelay & fxSleep — the async helpers used above