nanomath/src/number/helpers.js
Glen Whitney 8da23a84be
All checks were successful
/ test (pull_request) Successful in 17s
feat: Add complex argument function arg
Also removes circular imports from nanomath
2025-04-24 13:09:15 -07:00

16 lines
589 B
JavaScript

import {NumberT} from './NumberT.js'
import {Returns} from '#core/Type.js'
import {match} from '#core/TypePatterns.js'
export const plain = f => match(
Array(f.length).fill(NumberT), Returns(NumberT, f))
// Takes a behavior returning boolean, and returns a factory
// that returns that behavior if the boolean type is present,
// and otherwise wraps the behavior to return 1 or 0.
export const boolnum = behavior => math => {
const {BooleanT} = math.types
if (BooleanT) return Returns(BooleanT, behavior)
return Returns(NumberT, (...args) => behavior(...args) ? 1 : 0)
}