prepend

Yields one value first, then all values of the source.

Iterable<A> prepend<A>(A a, Iterable<A> iterable) FxAsyncIterable<A> prependAsync<A>(FutureOr<A> a, FxAsyncIterable<A> iterable) Fx<T> Fx.prepend(T a) // chain FxAsync<T> FxAsync.prepend(FutureOr<T> a)

Lecture

prepend is append's mirror: it yields a first, then falls through to the source. Since the source itself is untouched until it's actually pulled, prepending is cheap regardless of how expensive or large the source is — no copying, no shifting indices, just one extra value ahead of the rest.

prependAsync accepts a Future for a as well; it's awaited first, before the first pull reaches the underlying source.

Demo 1 · Basics

Demo 2 · Async, with a future value

Try it yourself

Exercise: prepend 'mix' to the front of the steps.

Related: append — add a value at the end instead · concat — join two full iterables · reverse