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 materializes the
whole source into a list internally before yielding anything, 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: takeLastAsync
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.