Function

This module contains some basic function utilities. Something to note is that purify doesn't expose a compose or pipe function - that is because in JavaScript/TypeScript using those functions is not ergonomic and is prone to type errors related to generics.
How to import
import { Order, identity, always, ... } from 'purify-ts/Function'

Exports

identity
a -> a<T>(x: T): T
The identity function, returns the value it was given.
always
a -> b -> a<T>(x: T): <U>(y: U) => T
Returns a function that always returns the same value. Also known as `const` in other languages.
[1, 2, 3, 4].map(always(0))
[0, 0, 0, 0]
curry
<TArgs extends any[], TReturn>(fn: (...args: TArgs) => TReturn): CurriedFn<TArgs, TReturn>
Takes a function that receives multiple arguments and returns a "curried" version of that function that can take any number of those arguments and if they are less than needed a new function that takes the rest of them will be returned.
const sum3 = (
  x: number, y: number, z: number
) => x + y + z

const curriedSum3 = curry(sum3)
curriedSum3(1)       // (y: number, z: number) => number
curriedSum3(1, 2)    // (z: number) => number
curriedSum3(1, 2, 3) // number
curriedSum3(1)(2)(3) // number
curriedSum3(1, 2)(3) // number
compose/flow/pipe
There is no such function in purify! Unfortunately it's not possible to provide a type-safe version of compose and friends, so until TypeScript allows us to do that purify will not have them.
compare
a -> b -> Order<T>(x: T, y: T): Order
Compares two values using the default "<" and ">" operators.
compare(1, 10)
compare('a', 'a')
compare(10, 1)
Order.LT
Order.EQ
Order.GT
orderToNumber
Order -> Int(order: Order): number
Maps the Order enum to the values expected by the standard ECMAScript library when doing comparison (Array.prototype.sort, for example).
orderToNumber(Order.LT)
orderToNumber(Order.EQ)
orderToNumber(Order.GT)
-1
0
1