2025-04-13 16:29:51 +00:00
|
|
|
import {NumberT} from './NumberT.js'
|
2025-04-02 11:22:53 -07:00
|
|
|
|
2025-04-08 22:42:53 +00:00
|
|
|
import {onType} from '#core/helpers.js'
|
|
|
|
import {Returns} from '#core/Type.js'
|
|
|
|
|
2025-04-02 11:22:53 -07:00
|
|
|
export const plain = f => onType(
|
2025-04-13 16:29:51 +00:00
|
|
|
Array(f.length).fill(NumberT), Returns(NumberT, f))
|
|
|
|
|
2025-04-15 01:17:27 -07:00
|
|
|
// 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)
|
|
|
|
}
|