preamble 0.0.1 → 0.0.2
raw patch · 2 files changed
+57/−2 lines, 2 files
Files
- preamble.cabal +1/−1
- src/Preamble/Prelude.hs +56/−1
preamble.cabal view
@@ -1,5 +1,5 @@ name: preamble-version: 0.0.1+version: 0.0.2 synopsis: Yet another prelude. homepage: https://github.com/swift-nav/preamble license: MIT
src/Preamble/Prelude.hs view
@@ -1,11 +1,66 @@ {-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE OverloadedStrings #-} -- | Local Prelude. --- module Preamble.Prelude ( module Exports+ , maybe'+ , maybe_+ , eitherThrowIO+ , maybeThrowIO+ , boolThrowIO+ , textFromString+ , (-/-)+ , (-.-)+ , (-:-) ) where import BasicPrelude as Exports import Control.Lens as Exports hiding (uncons, (.=), (<.>))+import Data.Text++-- | maybe with hanging function.+--+maybe' :: Maybe a -> b -> (a -> b) -> b+maybe' m b a = maybe b a m++-- | Maybe that returns () if Nothing+--+maybe_ :: Monad m => Maybe a -> (a -> m ()) -> m ()+maybe_ = flip $ maybe $ return ()++-- | Throw userError on either error.+--+eitherThrowIO :: MonadIO m => Either String a -> m a+eitherThrowIO = either (liftIO . throwIO . userError) return++-- | Throw userError on maybe nothing.+--+maybeThrowIO :: MonadIO m => String -> Maybe a -> m a+maybeThrowIO s = maybe (liftIO $ throwIO $ userError s) return++-- | Throw userError on false.+--+boolThrowIO :: MonadIO m => String -> Bool -> m ()+boolThrowIO = flip unless . liftIO . throwIO . userError++-- | Reverse of textToString+--+textFromString :: String -> Text+textFromString = pack++-- | </> for IsString.+--+(-/-) :: (IsString s, Monoid s) => s -> s -> s+(-/-) = (<>) . (<> "/")++-- | <.> for IsString.+--+(-.-) :: (IsString s, Monoid s) => s -> s -> s+(-.-) = (<>) . (<> ".")++-- | <:> for IsString.+--+(-:-) :: (IsString s, Monoid s) => s -> s -> s+(-:-) = (<>) . (<> ":")