summaryrefslogtreecommitdiff
path: root/Alpha.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-02-10 18:04:12 -0500
committerBen Sima <ben@bsima.me>2021-02-17 20:27:39 -0500
commitad3102e108562aa7c12e89991eb387cd3aa359ae (patch)
tree542407f91c0a2d78f529eccc1d0ee58df10156aa /Alpha.hs
parent81dc733f5138aa0720eb2f6382bb91b33e1661cc (diff)
Add boolean and logging pipeline operators
Diffstat (limited to 'Alpha.hs')
-rw-r--r--Alpha.hs35
1 files changed, 27 insertions, 8 deletions
diff --git a/Alpha.hs b/Alpha.hs
index 697f096..8fdca51 100644
--- a/Alpha.hs
+++ b/Alpha.hs
@@ -42,12 +42,17 @@ module Alpha
(<%),
(%>),
- -- * inding
+ -- * Binding
bind,
(+>),
-- * Bool
don't,
+ (?>),
+ (?<),
+ (?:),
+ (?.),
+ (?+),
-- * Text
tshow,
@@ -66,9 +71,6 @@ module Alpha
-- * Data Validation
require,
-
- -- * Debugging tools
- say,
)
where
@@ -85,10 +87,6 @@ import qualified Prelude
list :: a -> [a]
list a = [a]
--- | Debugging printf
-say :: Text -> IO ()
-say = putText
-
-- | Composition
compose :: (a -> b) -> (b -> c) -> (a -> c)
compose f g x = g (f x)
@@ -163,6 +161,27 @@ a +> b = a Prelude.>>= b
infixl 1 +>
+-- | If-then-else. wutcol
+(?:) :: Bool -> (Bool -> p, Bool -> p) -> p
+a ?: (f, g) = if a then f a else g a
+
+-- | Inverted if-then-else. wutdot
+(?.) :: Bool -> (Bool -> p, Bool -> p) -> p
+a ?. (g, f) = if a then f a else g a
+
+-- | Positive assertion. wutgar
+(?>) :: Bool -> (Bool -> Text -> a) -> Text -> a
+a ?> f = if a then f a else panic "wutgar failed"
+
+-- | Lisp-style cond. wutlus
+(?+) :: t -> [(t -> Bool, p)] -> p
+a ?+ ((p, v) : ls) = if p a then v else a ?+ ls
+_ ?+ [] = panic "wutlus: empty cond list"
+
+-- | Negative assertion. wutgal
+(?<) :: Bool -> (Bool -> Text -> a) -> Text -> a
+a ?< f = if not a then f a else panic "wutgal failed"
+
-- | Removes newlines from text.
chomp :: Text -> Text
chomp = Text.filter (/= '\n')