Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
✅[#1] Change some operations to support "truthyness"
Browse files Browse the repository at this point in the history
Changes "if", "filter", "and" and "or" to take any type as arguments
but the return types should still align.

This change just assumes an implicit "!!" call around the boolean arguments.
  • Loading branch information
CharString committed Nov 9, 2023
1 parent 47a96ee commit 84a627a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const defaultContext = makeContext({
missing: f(array(string), array(string)),
missing_some: f(number, array(string), array(string)),
// Logic and Boolean Operations
if: forall([a], f(bool, a, a, a)),
if: forall([a, b], f(a, b, b, b)),
// TODO: should the parameters of (in-)equaility be of the same type 🤔
// forcing === and !== isn't a eslint rule for nothing...
'==': forall([a, b], f(a, b, bool)),
Expand All @@ -55,8 +55,8 @@ export const defaultContext = makeContext({
'!==': forall([a, b], f(a, b, bool)),
'!': forall([a], f(a, bool)),
'!!': forall([a], f(a, bool)),
or: f(bool, bool, bool),
and: f(bool, bool, bool),
or: forall([a, b], f(a, b, bool)),
and: forall([a, b], f(a, b, bool)),
// Numeric Operations
'>': f(number, number, bool),
'>=': f(number, number, bool),
Expand All @@ -80,8 +80,8 @@ export const defaultContext = makeContext({
// Array Operations
// forall a b. :: [a] -> (a -> b) -> [b]
map: forall([a, b], f(array(a), f(a, b), array(b))),
// forall a. :: [a] -> (a -> bool) -> [a]
filter: forall([a], f(array(a), f(a, bool), array(a))),
// forall a truthy. :: [a] -> (a -> truthy) -> [a]
filter: forall([a, b], f(array(a), f(a, b), array(a))),
// forall a b. :: [b] -> (a -> b -> a) -> a -> a
reduce: forall([a, b], f(array(b), f(a, b, a), a, a)),
// forall a. :: [a] -> (a -> bool) -> bool
Expand Down

0 comments on commit 84a627a

Please sign in to comment.