Skip to content

M (Math)

The five dual arithmetic operations appear with both shapes in the complete dual-call catalogue.

inc(n: number): number
dec(n: number): number
negate(n: number): number
product(arr: number[]): number
add(a: number, b: number): number
add(b: number): (a: number) => number
subtract(a: number, b: number): number
subtract(b: number): (a: number) => number
multiply(a: number, b: number): number
multiply(b: number): (a: number) => number
divide(a: number, b: number): number
divide(b: number): (a: number) => number
modulo(a: number, b: number): number
modulo(b: number): (a: number) => number
import { pipe } from '@stopcock/fp'
import * as A from '@stopcock/fp/array'
import * as M from '@stopcock/fp/math'
// apply discount
pipe(prices, A.map(M.multiply(0.9))) // 10% off
// offset scores
pipe(rawScores, A.map(M.add(curve)))
// compound product
M.product([2, 3, 4]) // 24
// counter operations
pipe(count, M.inc) // count + 1
pipe(count, M.dec) // count - 1
pipe(value, M.negate) // -value
// both call shapes
M.modulo(17, 5) // 2, direct data-first
pipe(17, M.modulo(5)) // 2, curried data-last