nanomath/src/number/type.js
Glen Whitney 5bee93dbb3
All checks were successful
/ test (pull_request) Successful in 19s
refactor: prepare for boolean functions
* Defines a BooleanT type
  * adds options to the Type constructor, so far just to allow conversions
    from other types
  * renames Number type to NumberT
  * records the name of types, and puts the name in the string representation
  * defines a conversion fron BooleanT to NumberT, specified to be automatic
  * stub code for automatic conversions, not yet complete
  * BooleanT not yet added to nanomath

Checked that the new facilities do not disrupt the prior behavior on numbers.
2025-04-10 14:01:45 -07:00

7 lines
255 B
JavaScript

import {plain} from './helpers.js'
import {BooleanT} from '#boolean/BooleanT.js'
import {Returns} from '#core/Type.js'
import {NumberT} from '#number/NumberT.js'
export const number = plain(a => a)
number.also(BooleanT, Returns(NumberT, a => a ? 1 : 0))