From ad3102e108562aa7c12e89991eb387cd3aa359ae Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 10 Feb 2021 18:04:12 -0500 Subject: Add boolean and logging pipeline operators --- Alpha.hs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'Alpha.hs') 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') -- cgit v1.2.3