minBy
The element whose key is smallest — one walk, no sort, null when empty.
A? minBy<A>(Object? Function(A a) f, Iterable<A> iterable)
Future<A?> minByAsync<A>(Object? Function(A a) f, FxAsyncIterable<A> iterable)
T? Fx<T>.minBy(Object? Function(T a) f) // chain (sync)
Future<T?> FxAsync<T>.minBy(Object? Function(T a) f) // chain (async)
Lecture
minBy is the mirror of
maxBy: it returns the
element with the smallest key after a single O(n) walk,
where sortBy(key).head() would sort the whole pipeline
just to read one value.
The contract matches maxBy exactly: keys compare like
sortBy
(Comparable.compare), ties keep the first
element encountered, and an empty pipeline returns null —
not infinity, which is what the numeric
min does, because there is no
"zero element" to fall back to.
Demo 1 · Basics, empty case & ties
Demo 2 · Async
Try it yourself
Exercise: find the fastest runner with one call.