このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

dropRight

Returns a lazy iterable that omits the last length values.

Iterable<A> fxDropRight<A>(int length, Iterable<A> iterable) FxAsyncIterable<A> fxDropRightAsync<A>(int length, FxAsyncIterable<A> iterable) Fx<T> Fx.dropRight(int count) // chain FxAsync<T> FxAsync.dropRight(int count)

Lecture

dropRight omits the last length values instead of the first. As with takeRight, there's no way to know which elements are "last" without looking ahead, so it needs a finite source. The sync version stays lazy, though: over a List it indexes straight to the cut-off, and over any other iterable it holds a small buffer of length elements and releases each value only once length newer ones have arrived. It's the right tool when you have, say, a known-size batch and want everything except a trailing footer or sentinel.

fxDropRightAsync is different: it awaits the entire upstream into a list before it can start producing values.

Demo 1 · Basics

Demo 2 · Async (must buffer the whole source first)

Try it yourself

Exercise: drop the last 2 footer lines.

Related: drop — drop from the front instead · takeRight — keep the last n instead of dropping them · reverse — materializes the whole source