ts-list-comprehension
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

List Comprehension for TypeScript

This library implements comprehension for arrys, sets and maps for TypeScript. It also offer a powerful library to construct populated arrays that can be used with the comprehension functions.

Examples

const titles = array(
  chars('a', 'z'), ['foo', 'bar', 'baz'],
  (c, t) => [c, t],
  (c, t) => t.startsWith(c)
)
// [ [ 'b', 'bar' ], [ 'b', 'baz' ], [ 'f', 'foo' ] ]
const matrix = array(
  zip(range(0, 3), repeat(range(0, 3))(4)),
  ([x, y]) => y.map(y => `${x}${y}`)
)
/*
[ [ '0, 0', '0, 1', '0, 2', '0, 3' ],
  [ '1, 0', '1, 1', '1, 2', '1, 3' ],
  [ '2, 0', '2, 1', '2, 2', '2, 3' ],
  [ '3, 0', '3, 1', '3, 2', '3, 3' ] ]
*/

Array constructors

let range: (a: number, b: number, step = 1) => number[]
let repeat: <a>(...sequence: a[]) => (times: number) => a[]
let zip: <a, b>(a: a[], b: b[]) => [a, b][]
let zip: <a, b, c>(a: a[], b: b[], c: c[])[a, b, c][]
let zip: <a, b, c, d>(a: a[], b: b[], c: c[], d: d[]) => [a, b, c, d][]
let zip: <a, b, c, d, e>(a: a[], b: b[], c: c[], d: d[], e: e[]) => [a, b, c, d, e][]
let zip: <a, b, c, d, e, f>(a: a[], b: b[], c: c[], d: d[], e: e[], f: f[]) => [a, b, c, d, e, f][]
let chars: chars = (a: char, b: char) => char[]

Package Sidebar

Install

npm i ts-list-comprehension

Weekly Downloads

35

Version

1.0.5

License

MIT

Unpacked Size

20.6 kB

Total Files

17

Last publish

Collaborators

  • wim_jongeneel