packages feed

hw-prelude 0.0.0.3 → 0.0.0.4

raw patch · 4 files changed

+132/−15 lines, 4 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ HaskellWorks.Error: onLeftM_ :: forall e a m. () => Monad m => m a -> m (Either e a) -> m a
+ HaskellWorks.Error: onLeft_ :: forall e a m. () => Monad m => m a -> Either e a -> m a
+ HaskellWorks.Error: onMany :: forall a m. () => Monad m => (NonEmpty a -> m (Maybe a)) -> [a] -> m (Maybe a)
+ HaskellWorks.Error: onManyM :: forall a m. () => Monad m => (NonEmpty a -> m (Maybe a)) -> m [a] -> m (Maybe a)
+ HaskellWorks.Error: onManyM_ :: forall a m. () => Monad m => m (Maybe a) -> m [a] -> m (Maybe a)
+ HaskellWorks.Error: onMany_ :: forall a m. () => Monad m => m (Maybe a) -> [a] -> m (Maybe a)
+ HaskellWorks.Prelude: onLeft :: forall e a m. () => Monad m => (e -> m a) -> Either e a -> m a
+ HaskellWorks.Prelude: onLeftM :: forall e a m. () => Monad m => (e -> m a) -> m (Either e a) -> m a
+ HaskellWorks.Prelude: onLeftM_ :: forall e a m. () => Monad m => m a -> m (Either e a) -> m a
+ HaskellWorks.Prelude: onLeft_ :: forall e a m. () => Monad m => m a -> Either e a -> m a
+ HaskellWorks.Prelude: onMany :: forall a m. () => Monad m => (NonEmpty a -> m (Maybe a)) -> [a] -> m (Maybe a)
+ HaskellWorks.Prelude: onManyM :: forall a m. () => Monad m => (NonEmpty a -> m (Maybe a)) -> m [a] -> m (Maybe a)
+ HaskellWorks.Prelude: onManyM_ :: forall a m. () => Monad m => m (Maybe a) -> m [a] -> m (Maybe a)
+ HaskellWorks.Prelude: onMany_ :: forall a m. () => Monad m => m (Maybe a) -> [a] -> m (Maybe a)
+ HaskellWorks.Prelude: onNothing :: forall a m. () => Monad m => m a -> Maybe a -> m a
+ HaskellWorks.Prelude: onNothingM :: forall a m. () => Monad m => m a -> m (Maybe a) -> m a
+ HaskellWorks.ToText: class ToText a
+ HaskellWorks.ToText: instance HaskellWorks.ToText.ToText Data.Text.Internal.Builder.Builder
+ HaskellWorks.ToText: instance HaskellWorks.ToText.ToText Data.Text.Internal.Lazy.Text
+ HaskellWorks.ToText: instance HaskellWorks.ToText.ToText Data.Text.Internal.Text
+ HaskellWorks.ToText: instance HaskellWorks.ToText.ToText GHC.Base.String
+ HaskellWorks.ToText: toText :: ToText a => a -> Text

Files

hw-prelude.cabal view
@@ -1,6 +1,6 @@ cabal-version:          3.4 name:                   hw-prelude-version:                0.0.0.3+version:                0.0.0.4 synopsis:               Opinionated prelude library description:            Opinionated prelude library. license:                Apache-2.0@@ -96,5 +96,6 @@                         HaskellWorks.IO.Network.Socket                         HaskellWorks.IO.Process                         HaskellWorks.Prelude+                        HaskellWorks.ToText                         HaskellWorks.Unsafe   hs-source-dirs:       src
src/HaskellWorks/Error.hs view
@@ -1,28 +1,107 @@ module HaskellWorks.Error-  ( onLeft,-    onNothing,-    onLeftM,+  ( onNothing,     onNothingM,+    onLeft,+    onLeftM,+    onLeft_,+    onLeftM_,+    onMany,+    onManyM,+    onMany_,+    onManyM_,   ) where -import           HaskellWorks.Prelude--onLeft :: forall e a m. ()-  => Monad m-  => (e -> m a) -> Either e a -> m a-onLeft f = either f pure+import           Control.Applicative+import           Control.Monad+import           Data.Either+import           Data.Function+import           Data.List.NonEmpty+import           Data.Maybe +-- | Handle the case where a value is 'Nothing'. onNothing :: forall a m. ()   => Monad m-  => m a -> Maybe a -> m a+  => m a+  -> Maybe a+  -> m a onNothing h = maybe h return +-- | Handle the case where an effectful function returns 'Nothing'.+onNothingM :: forall a m. ()+  => Monad m+  => m a+  -> m (Maybe a)+  -> m a+onNothingM h f = onNothing h =<< f++-- | Handle the case where a value is 'Left'.+onLeft :: forall e a m. ()+  => Monad m+  => (e -> m a)+  -> Either e a+  -> m a+onLeft f = either f pure++-- | Handle the case where an effectful function returns 'Left'. onLeftM :: forall e a m. ()   => Monad m-  => (e -> m a) -> m (Either e a) -> m a+  => (e -> m a)+  -> m (Either e a)+  -> m a onLeftM f action = onLeft f =<< action -onNothingM :: forall a m. ()+-- | Handle the case where a value is 'Left'.+onLeft_ :: forall e a m. ()   => Monad m-  => m a -> m (Maybe a) -> m a-onNothingM h f = onNothing h =<< f+  => m a+  -> Either e a+  -> m a+onLeft_ f = either (const f) pure++-- | Handle the case where an effectful function returns 'Left'.+onLeftM_ :: forall e a m. ()+  => Monad m+  => m a+  -> m (Either e a)+  -> m a+onLeftM_ f action = onLeft_ f =<< action++-- | Handle the case where a list with many (more than one) elements.+onMany :: forall a m.()+  => Monad m+  => (NonEmpty a -> m (Maybe a))+  -> [a]+  -> m (Maybe a)+onMany h as = case as of+    []       -> pure Nothing+    [x]      -> pure (Just x)+    (x : xs) -> h (x :| xs)++-- | Handle the case where an effectul function returns a list with many (more than one) elements.+onManyM :: forall a m.()+  => Monad m+  => (NonEmpty a -> m (Maybe a))+  -> m [a]+  -> m (Maybe a)+onManyM h f =+  f >>= onMany h++-- | Handle the case where a list with many (more than one) elements.+onMany_ :: forall a m.()+  => Monad m+  => m (Maybe a)+  -> [a]+  -> m (Maybe a)+onMany_ h as = case as of+    []  -> pure Nothing+    [x] -> pure (Just x)+    _   -> h++-- | Handle the case where an effectul function returns a list with many (more than one) elements.+onManyM_ :: forall a m.()+  => Monad m+  => m (Maybe a)+  -> m [a]+  -> m (Maybe a)+onManyM_ h f =+  f >>= onMany_ h
src/HaskellWorks/Prelude.hs view
@@ -165,6 +165,17 @@     IOException,     IOError,     SomeException(..),++    onNothing,+    onNothingM,+    onLeft,+    onLeftM,+    onLeft_,+    onLeftM_,+    onMany,+    onManyM,+    onMany_,+    onManyM_,   ) where  import           Control.Applicative@@ -196,6 +207,7 @@ import           GHC.Num import           GHC.Real import           GHC.Stack+import           HaskellWorks.Error import           Prelude import           System.FilePath 
+ src/HaskellWorks/ToText.hs view
@@ -0,0 +1,25 @@+module HaskellWorks.ToText+  ( ToText (..)+  ) where++import           Data.Function+import           Data.String            (String)+import           Data.Text              (Text)+import qualified Data.Text              as T+import qualified Data.Text.Lazy         as LT+import qualified Data.Text.Lazy.Builder as TB++class ToText a where+  toText :: a -> Text++instance ToText String where+  toText = T.pack++instance ToText Text where+  toText = id++instance ToText LT.Text where+  toText = LT.toStrict++instance ToText TB.Builder where+  toText = LT.toStrict . TB.toLazyText