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-transform.nix

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

Module Description

Stream transformation operations - mapping and filtering

Combinators

filter

Keeps only elements matching a predicate.

Lazily filters stream, skipping elements that don’t match. May need to evaluate multiple steps to find next match.

Type Signature

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

Parameters

  • pred: Predicate function
  • stream: Source stream

Example

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

See Also

  • takeWhile - Take until predicate fails
  • map - Transform all elements

map

Transforms each element in a stream.

Applies a pure function to every value in the stream, preserving structure and laziness.

Type Signature

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

Parameters

  • f: Transformation function
  • stream: Source stream

Example

runFx (toList (map (x: x * 2) (fromList [1 2 3])))
# => [2 4 6]

See Also

  • filter - Select elements
  • flatMap - Transform and flatten

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