js-lists
Install
npm install lists-js
Using
import {cons, head, tail, isEmpty, toString, has, count, reverse, isList, push,
concat, map, filter, reduce, } from 'lists-js'
const list = cons(1, 2, 3); // (1, 2, 3)
head(list); // 1
tail(list); // (2, 3)
isList(list); // true
isList('text'); // false
push(0, list); // (0, 1, 2, 3)
toString(list); // (1, 2, 3)
has(3, list); // true
count(list); // 3
Documentation
Table of Contents
cons
Make a list
Parameters
args
...any
Examples
; // (1, 2, 3); // ()
Returns list
isList
Check if arguments is list
Parameters
list
Examples
; // true; // true; // false
Returns boolean
head
Get head element
Parameters
list
Examples
; // 1
Returns any
tail
Get tail element
Parameters
list
Examples
; // (2, 3)
Returns any
isEmpty
Check if list is empty
Parameters
list
Examples
; // false; //true
Returns boolean
push
Add element to list
Parameters
element
list
Examples
; // (3, 2, 1)
Returns list
toString
Convert list to string
Parameters
list
Examples
; // (1, 2, 3);; // (1, (2, 3));
Returns string
has
Check if list has an element
Parameters
value
list
Examples
; // true; // false
Returns boolean
count
Get number of elements in a list
Parameters
list
Examples
; // 3; // 0
Returns int
reverse
Reverse list
Parameters
list
Examples
; // (3, 2, 1)
Returns list
concat
Join 2 lists
Parameters
list1
list2
Examples
; // (1, 2, 3, 4)
Returns list
map
Map list
Parameters
f
list
Examples
const list = ;; // (1, 4, 9)
Returns list
filter
Filter list
Parameters
f
list
Examples
const list = ;; // (2, 9)
Returns list
reduce
Reduce list
Parameters
f
acc
elements
Examples
; // 3
Returns any