M (Math)
The five dual arithmetic operations appear with both shapes in the complete dual-call catalogue.
Single-argument
Section titled “Single-argument”inc(n: number): numberdec(n: number): numbernegate(n: number): numberproduct(arr: number[]): numberDual-form
Section titled “Dual-form”add(a: number, b: number): numberadd(b: number): (a: number) => numbersubtract(a: number, b: number): numbersubtract(b: number): (a: number) => numbermultiply(a: number, b: number): numbermultiply(b: number): (a: number) => numberdivide(a: number, b: number): numberdivide(b: number): (a: number) => numbermodulo(a: number, b: number): numbermodulo(b: number): (a: number) => numberExamples
Section titled “Examples”import { pipe } from '@stopcock/fp'import * as A from '@stopcock/fp/array'import * as M from '@stopcock/fp/math'
// apply discountpipe(prices, A.map(M.multiply(0.9))) // 10% off
// offset scorespipe(rawScores, A.map(M.add(curve)))
// compound productM.product([2, 3, 4]) // 24
// counter operationspipe(count, M.inc) // count + 1pipe(count, M.dec) // count - 1pipe(value, M.negate) // -value
// both call shapesM.modulo(17, 5) // 2, direct data-firstpipe(17, M.modulo(5)) // 2, curried data-last