psxcode / arity

Functional helpers with Typescript types propagation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arity

Functional helpers, with Typescript type propagation

Install

npm install @psxcode/arity

nullary

import { nullary } from '@psxcode/arity'

const f: (p0: number, p1: string) => boolean

typeof nullary(f)  // () => boolean

unary

import { unary } from '@psxcode/arity'

const f: (p0: number, p1: string) => boolean

typeof unary(f)  // (p0: number) => boolean

binary

import { binary } from '@psxcode/arity'

const f: (p0: number, p1: string, p2: number) => boolean

typeof binary(f)  // (p0: number, p1: string) => boolean

ternary

import { ternary } from '@psxcode/arity'

const f: (p0: number, p1: string, p2: number, p3: string) => boolean

typeof ternary(f)  // (p0: number, p1: string, p2: number) => boolean

voidify

import { voidify } from '@psxcode/arity'

const f: (p0: number, p1: string) => boolean

typeof voidify(f)  // (p0: number, p1: string) => void

bind

import { bind } from '@psxcode/arity'

const f: (p0: number, p1: string, p2: boolean) => boolean

typeof bind(10)(f)  // (p0: string, p1: boolean) => boolean

typeof bind(10, 'str')(f)  // (p1: boolean) => boolean

typeof bind(10, 'str', true)(f)  // () => boolean

bindCtx

import { bindCtx } from '@psxcode/arity'

const ctx: { [k: string]: any }
const f: (this: typeof ctx, p0: number) => boolean

typeof bindCtx(ctx)(f)  // (p0: number) => boolean

bindProps

import { bindProps } from '@psxcode/arity'

const props: {
  a: number,
  b: string
}
const f: (p: typeof props) => boolean

typeof bindProps({ a: 10 })(f)  // (p: { b: string }) => boolean

curry

import { curry } from '@psxcode/arity'

const f: (a: number, b: string) => boolean

typeof curry(f)  // (a: number) => (b: string) => boolean

gather

import { gather } from '@psxcode/arity'

const f: (p: [number, string, boolean]) => boolean

typeof gather(f)  // (p0: number, p1: string, p2: boolean) => boolean

spread

import { spread } from '@psxcode/arity'

const f: (a: number, b: string, c: boolean) => boolean

typeof spread(f)  // (args: [number, string, boolean]) => boolean

branch

import { branch } from '@psxcode/arity'

const f0: (a: number) => string
const f1: (a: number) => number
const pred = (a: number) => true

typeof branch(pred, f0)  // (a: number) => string | undefined

typeof branch(pred, f0, f1)  // (a: number) => string | number

and

import { and } from '@psxcode/arity'

const f0: (a: number) => boolean
const f1: (a: number) => boolean

typeof and(f0, f1)  // (a: number) => boolean

or

import { or } from '@psxcode/arity'

const f0: (a: number) => boolean
const f1: (a: number) => boolean

typeof or(f0, f1)  // (a: number) => boolean

noop

import { noop } from '@psxcode/arity'

typeof noop  // () => void

identity

import { identity } from '@psxcode/arity'

typeof identity  // <T> (a: T) => T

identityAsync

import { identityAsync } from '@psxcode/arity'

typeof identityAsync  // <T> (a: T) => Promise<T>

constant

import { constant } from '@psxcode/arity'

typeof constant  // <T> (a: T) => () => T

constantAsync

import { constantAsync } from '@psxcode/arity'

typeof constantAsync  // <T> (a: T) => () => Promise<T>

About

Functional helpers with Typescript types propagation

License:MIT License


Languages

Language:TypeScript 98.9%Language:JavaScript 1.1%