Skip to content

Commit 42a59d1

Browse files
authored
Merge pull request #10 from LiamGoodacre/feature/boolean-if
Add typelevel boolean if
2 parents 6e8b196 + 2bf6ae6 commit 42a59d1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Type/Data/Boolean.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ module Type.Data.Boolean
1212
, or
1313
, class Not
1414
, not
15+
, class If
16+
, if_
1517
) where
1618

19+
import Type.Proxy (Proxy(..))
20+
1721
foreign import kind Boolean
1822
foreign import data True :: Boolean
1923
foreign import data False :: Boolean
@@ -64,3 +68,15 @@ instance notFalse :: Not False True
6468

6569
not :: forall i o. Not i o => BProxy i -> BProxy o
6670
not _ = BProxy
71+
72+
-- | If - dispatch based on a boolean
73+
class If (bool :: Boolean)
74+
(onTrue :: Type)
75+
(onFalse :: Type)
76+
(output :: Type) |
77+
bool -> onTrue onFalse output
78+
instance ifTrue :: If True onTrue onFalse onTrue
79+
instance ifFalse :: If False onTrue onFalse onFalse
80+
81+
if_ :: forall b t e o. If b t e o => BProxy b -> Proxy t -> Proxy e -> Proxy o
82+
if_ _ _ _ = Proxy

0 commit comments

Comments
 (0)