0.18.0 • Published 11 months ago

@otpjs/types v0.18.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

@otpjs/types

A collection of types used in the otpjs ecosystem.

Usage

Installation

npm i @otpjs/types

Usage

// Full specification
import { Tuple, List, improperList, Pid, Ref, OTPError } from '@otpjs/types';

// Shorthand helpers
import { t, l, il, cons, cdr, car } from '@otpjs/types';

Tuple/t

Composes a tuple from an arbitrary number of terms. Internal implementation is an array, but cannot expand.

const tuple = t(1, 2, 3); // {1, 2, 3}

// Accessors are 0 indexed
tuple.get(1); // 2
tuple[2]; // 3

// Update a value
tuple.set(0, 2); // {2, 2, 3}
tuple[2] = 4; // {1, 2, 4}

// Iterable
for (let term of tuple) {
    // ...
}

// Destructuring assignment
const [a, b, c] = t(1, 2, 3);

List and helpers

A List is a singly-linked list.

Helpers
nil

A special symbol represents nil, or an empty list. We wrap this symbol in an Object to provide certain functionality.

l

Equivalent to List.from. Accepts an arbitrary number of elements and composes a list from them.

const list = l(1, 2, 3, 4, 5, 6); // [1, 2, 3, 4, 5, 6]
improperList/il

Create an "improper" list with a non-list, non-nil tail. Accepts an arbitrary number of elements. The last element provided will be the tail.

const improper = il(1, 2); // [ 1 | 2 ]
cons

Construct a new list node from an element (the head) and an existing list (the tail). Can construct improper lists.

let list = cons(0, nil); // [0]
list = cons(1, list); // [1, 0]
list = cons(2, list); // [2, 1, 0]
car/cdr

These helpers access the head and tail of a list node.

car accesses the head. cdr accesses the tail.

0.17.8

11 months ago

0.18.0

11 months ago

0.15.6

1 year ago

0.16.0

1 year ago

0.17.0

1 year ago

0.15.0

2 years ago

0.14.0

2 years ago

0.13.0

2 years ago

0.12.1

2 years ago

0.12.2

2 years ago

0.12.3

2 years ago

0.12.6

2 years ago

0.12.0

2 years ago

0.10.0

2 years ago

0.11.0

2 years ago

0.10.0-beta.21

2 years ago

0.10.0-beta.19

2 years ago

0.10.0-beta.18

2 years ago

0.10.0-beta.15

2 years ago

0.10.0-beta.13

2 years ago

0.10.0-beta.12

2 years ago

0.10.0-beta.11

2 years ago

0.10.0-beta.10

2 years ago

0.10.0-beta.5

2 years ago

0.10.0-beta.4

2 years ago

0.10.0-beta.2

2 years ago

0.10.0-beta.1

2 years ago

0.10.0-beta.0

2 years ago