From 46a680f7ca7def264a0f0b616883fb8e47271bab Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 12 Apr 2020 12:15:49 -0700 Subject: De-namespace Alpha A bunch of formatting changes got in there too. Oops. I will probably eventually de-namespace everything, mostly because I'm tired of typing "Com.Whatever.Thing" all the time. A better namespacing strategy might be to use normal Haskell namespacing (Data, Control, Network, etc) for code that is not specific to biz activities (i.e. if I could open-source it at any time), and use simply "Biz" for stuff that I would never want to open-source. --- Alpha.hs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Alpha.hs (limited to 'Alpha.hs') diff --git a/Alpha.hs b/Alpha.hs new file mode 100644 index 0000000..fe5c9df --- /dev/null +++ b/Alpha.hs @@ -0,0 +1,87 @@ +{-# LANGUAGE NoImplicitPrelude #-} +-- | Commonly useful functions, a Prelude replacement. +-- +-- This is designed to be imported everywhere, unqualified (generally +-- the only unqualified import you should use). +-- +-- Alpha can be opinionated and break with other Haskell idioms. For +-- example, we define our own operators which have a pattern to their +-- characters: +-- +-- - `|` normal function-level applications +-- - `/` indicates doing something inside a functor +-- - `<` and `>` indicate the direction in which values flow +-- between functions +-- +-- It seems unnecessarily different at first but it makes things easier +-- to read quickly. +module Alpha + ( + -- * Re-export Protolude + module X + -- * Applying + , (<|) + , (|>) + -- * Mapping + , (/>) + , () ) +import Data.String +import Data.Text ( Text ) +import qualified Data.Text as Text +import qualified Data.Text.Lazy as LazyText +import Protolude as X + +-- | Debugging printf +say :: Text -> IO () +say msg = putStrLn msg + +-- | Alias for map, fmap, <$> +( (a -> b) -> f a -> f b +( (a -> b) -> f0 (f1 a) -> f0 (f1 b) +( b) -> a -> b +(<|) = ($) +infixr 0 <| + +-- | Reverse function application. Do the left side, then pass the +-- return value to the function on the right side. +(|>) :: a -> (a -> b) -> b +(|>) = (&) + +-- | Alias for <&>. Can be read as "and then". Basically does into a +-- functor, does some computation, then returns the same kind of +-- functor. Could also be defined as `f >>= return . g` +(/>) :: Functor f => f a -> (a -> b) -> f b +(/>) = (<&>) + +-- | Removes newlines from text. +chomp :: Text -> Text +chomp = Text.filter (/= '\n') + +-- | Removes newlines from lazy text. +lchomp :: LazyText.Text -> LazyText.Text +lchomp = LazyText.filter (/= '\n') + +-- | Join a list of things with a separator. +joinWith :: [a] -> [[a]] -> [a] +joinWith = intercalate -- cgit v1.2.3