Hyperlinkv0.8.0-beta.28

Stream

Stream.runLastconsteffect/Stream.ts:10840
<A, E, R>(self: Stream<A, E, R>): Effect.Effect<Option.Option<A>, E, R>

Runs the stream and returns the last element as an Option.

When to use

Use to consume a finite stream when only the final emitted element matters.

Details

Option.some contains the last emitted element. Option.none means the stream completed without emitting.

Gotchas

The returned effect waits for the stream to complete before it can produce a value.

export const runLast = <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Option.Option<A>, E, R> =>
  Effect.map(Channel.runLast(self.channel), Option.map(Arr.lastNonEmpty))