Skip to content

runarberg/andcetera

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

&cetera

Functional iterator helpers

&cetera (pronounced andcetera) is an iterable helper library (similar to itertools) but with a functional twist. Every operator is a function that returns a function that consumes a passed in iterable, operate on its iterator and returns another iterable. This is optimized to be used in pipelines.

import { map, pipe, range, reduce } from "andcetera";

// Sum of the first five squares.
pipe(
  range(1, 6),
  map((n) => n ** 2),
  reduce((sum, square) => sum + square, 0),
);
// => 55

Or if you use the proposed pipeline operator:

import { aside, drop, map, range, reduce, take } from "andcetera/sync";

// Sum of the first five squares and log them to the console as they pass by.
range()
  |> drop(1)
  |> take(5)
  |> map((n) => n ** 2)
  |> aside((square) => console.log(square))
  |> reduce((sum, square) => sum + square, 0);
// => 55
// Logs 1, 4, 9, 16, 25

About

Iterator helpers with a functional twist

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published