Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

stream-stream-limit.nix

Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/stream-limit.nix

Module Description

Stream limiting operations - taking first n elements or while condition holds

Combinators

take

Takes first n elements from stream.

Terminates after n elements even if source continues. Enables working with infinite streams.

Type Signature

Int -> Stream<S, V> -> Stream<S, V>

Parameters

  • n: Number of elements to take
  • stream: Source stream

Example

runFx (toList (take 2 (fromList [1 2 3 4])))
# => [1 2]

See Also

  • takeWhile - Take until condition
  • filter - Conditional selection

takeWhile

Takes elements while predicate holds.

Terminates on first element that doesn’t match predicate.

Type Signature

(V -> Bool) -> Stream<S, V> -> Stream<S, V>

Parameters

  • pred: Predicate to test
  • stream: Source stream

Example

runFx (toList (takeWhile (x: x < 3) (fromList [1 2 3 4])))
# => [1 2]

See Also

  • take - Take fixed number
  • filter - Keep all matching

Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/stream-limit.nix