takeLast
Returns a lazy iterable of the last length values from a source.
Lecture
takeLast is take's mirror image: instead of
the first length values, you get the last ones. There's a
catch, though — to know what the "last" values are, takeLast
has to see every element first. It has to consume the
whole source before yielding anything (a List is indexed
directly; any other source is read through a ring buffer holding only the
last length elements), so unlike most FxDart operators it
does not work on infinite sequences.
takeLast is the Dart-idiomatic name; fxdart also accepts the
FxTS spelling takeRight — they're the same operator.
The async version has the same constraint: fxTakeLastAsync
drains the entire upstream (awaiting every element) before it can hand
back the tail. Reach for it only when you know the source is finite and
small enough to buffer.
Demo 1 · Basics
Demo 2 · Async (must buffer the whole source first)
Try it yourself
Exercise: keep only the last 3 scores.