npm.io
1.1.2 • Published 3 years ago

functional-tools

Licence
MIT
Version
1.1.2
Deps
0
Size
3 kB
Vulns
0
Weekly
0

Functional Tools

Fully typed utility functions to write Typescript in a more functional style

Installation

npm i --save functional-tools
yarn add functional-tools

Basic Example

Evaluate

import { evaluate } from "./evaluate";

const startsWithH = (x: string) => x[0] === "h";

const hasAComma = (x: string) => x.includes(",");

const result = evaluate("hello, world", startsWithH, hasAComma);

console.log(result);
// true
Pipeline Function
import { pipeline } from "functional-tools";

const append = (x: string) => (y: string) => y + x;

const capitalize = (x: string) => x.toUpperCase();

const removeWhitespace = (x: string) => x.replace(/ /g, "");

const helloWorld = pipeline("  hello", append(", world! "), capitalize, removeWhitespace);

console.log(helloWorld);
// "HELLO,WORLD!"

Keywords