2025-04-13 16:29:51 +00:00
|
|
|
import {BooleanT} from './BooleanT.js'
|
2025-04-25 14:17:34 +00:00
|
|
|
import {match} from '#core/TypePatterns.js'
|
2025-04-26 00:20:30 -07:00
|
|
|
import {Returns, TypeOfTypes, Undefined} from '#core/Type.js'
|
2025-04-13 16:29:51 +00:00
|
|
|
import {NumberT} from '#number/NumberT.js'
|
|
|
|
|
|
|
|
const bool = f => Returns(BooleanT, f)
|
|
|
|
|
refactor: change onType to match and take only one pattern and result (#22)
Pursuant to #12. Besides changing the name of onType to match, and only allowing one pattern and result in `match()`,
this PR also arranges that in place of an onType with lots of alternating PATTERN, VALUE, PATTERN, VALUE arguments, one now exports an _array_ of `match(PATTERN, VALUE)` items.
Doesn't quite fully resolve #12, because there is still the question of whether `match(...)` can be left out for a behavior that literally matches anything (current behavior), or whether `match(Passthru, behavior)` should be required for such cases.
Reviewed-on: https://code.studioinfinity.org/StudioInfinity/nanomath/pulls/22
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2025-04-22 05:01:21 +00:00
|
|
|
export const boolean = [
|
|
|
|
match(BooleanT, bool(p => p)),
|
|
|
|
match(NumberT, bool(a => !!a)),
|
|
|
|
match(TypeOfTypes, bool(() => true)),
|
|
|
|
match(Undefined, bool(() => false)),
|
|
|
|
match([], bool(() => false))
|
|
|
|
]
|