1.0.0 • Published 2 years ago

type-aligned v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Type Aligned

GitHub Workflow Status GitHub license npm semantic-release: gitmoji Twitter

Various abstract data types of type-aligned sequences. A type-aligned sequence is a heterogeneous sequence where the types enforce the element order.

Pipeline

A pipeline is a left-to-right composition of functions.

import { tap, pipe, feed } from "type-aligned";

const length = (s: string) => s.length;
const even = (n: number) => n % 2 === 0;

const pipeline = pipe(length, pipe(even, tap()));
const morphism = feed(pipeline);

console.log(morphism("Hello World!")); // true
console.log(morphism("hello world")); // false

Composition

A composition is a right-to-left composition of functions.

import { id, compose, apply } from "type-aligned";

const length = (s: string) => s.length;
const even = (n: number) => n % 2 === 0;

const composition = compose(even, compose(length, id()));
const morphism = apply(composition);

console.log(morphism("Hello World!")); // true
console.log(morphism("hello world")); // false