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

indexWhere

Returns the index of the first element for which a predicate is true, or -1.

int fxIndexWhere<A>(bool Function(A a) f, Iterable<A> iterable) Future<int> fxIndexWhereAsync<A>(FutureOr<bool> Function(A a) f, FxAsyncIterable<A> iterable) int Fx.indexWhere(bool Function(T a) f) // chain Future<int> FxAsync.indexWhere(FutureOr<bool> Function(T a) f) // chain int fxFindIndex<A>(bool Function(A a) f, Iterable<A> iterable) // FxTS alias

Lecture

indexWhere is the Dart-idiomatic name (cf. List.indexWhere); fxdart also accepts the FxTS spelling findIndex — they're the same operator. It's find's sibling: same lazy, short-circuiting scan, but it reports where the match was instead of the match itself. Note the different "nothing found" sentinel — this one is -1, an int, matching JavaScript's Array.prototype.findIndex. That's a deliberate contrast with head/find/nth, which all use null: an index has a natural "impossible" value, so FxDart keeps the FxTS convention here instead of inventing an int? return type.

The sync version is a counted loop that stops at the first element that passes f; the async version pairs each element with its index (via zipWithIndex) and stops at the first one that passes.

Demo 1 · Basics

Demo 2 · Short-circuiting & async

Try it yourself

Exercise: use indexWhere to find bob's position in the queue, or -1.

Related: find — same search, returns the value · fxIncludes — just "is it there?" · fxNth — the inverse: index in, value out · zipWithIndex — what powers the async version under the hood