packages feed

error-util (empty) → 0.0.1.1

raw patch · 4 files changed

+114/−0 lines, 4 filesdep +basedep +transformerssetup-changed

Dependencies added: base, transformers

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Piotr Młodawski++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ error-util.cabal view
@@ -0,0 +1,28 @@+name:                error-util+version:             0.0.1.1+synopsis:            Set of utils and operators for error handling+description:         Set of utils and operators for error handling+license:             MIT+license-file:        LICENSE+author:              Piotr Młodawski+maintainer:          Piotr Młodawski <remdezx+github@gmail.com>+homepage:            http://github.com/pmlodawski/error-util+bug-reports:         http://github.com/pmlodawski/error-util/issues+category:            Error Handling+build-type:          Simple+tested-with:         GHC == 7.8.4, GHC == 7.10.1, GHC == 7.10.2+cabal-version:       >=1.10++library+    exposed-modules:+        Control.Error.Operator+    default-language:   Haskell2010+    build-depends:      base >=4.7 && <4.9,+                        transformers > 0.4.0.0++    hs-source-dirs:     src+    default-language:   Haskell2010++source-repository head+    type:     git+    location: http://github.com/pmlodawski/error-util.git
+ src/Control/Error/Operator.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE FlexibleContexts #-}++module Control.Error.Operator (+    module Control.Error.Operator,+    module X,+) where++import           Control.Monad              (unless)+import           Control.Monad.Trans.Except as X+import qualified Data.Maybe                 as Maybe+import           Prelude+++--------------------------------------------------------------------------------+-- Either operators using `Left` to raise error+--------------------------------------------------------------------------------++infixl 4 <?>+(<?>) :: Maybe b -> a -> Either a b+val <?> m = Maybe.maybe (Left m) Right val++infixl 4 <?&>+(<?&>) :: Either a (Maybe b) -> a -> Either a b+val <?&> m = Maybe.maybe (Left m) Right =<< val++--------------------------------------------------------------------------------+-- ExceptT operators using `throwE` to raise error+--------------------------------------------------------------------------------++infixl 4 <??>+(<??>) :: Monad m => Maybe b -> a -> ExceptT a m b+val <??> m = Maybe.maybe (throwE m) return val++infixl 4 <??&>+(<??&>) :: Monad m => ExceptT a m (Maybe b) -> a -> ExceptT a m b+val <??&> m = Maybe.maybe (throwE m) return =<< val++--------------------------------------------------------------------------------+-- Simple monadic operators using `fail` to raise error+--------------------------------------------------------------------------------++infixl 4 <?.>+(<?.>) :: Monad m => Maybe b -> String -> m b+val <?.> m = Maybe.maybe (fail m) return val++infixl 4 <?&.>+(<?&.>) :: Monad m => m (Maybe b) -> String -> m b+val <?&.> m = Maybe.maybe (fail m) return =<< val++--------------------------------------------------------------------------------+-- Assertions+--------------------------------------------------------------------------------++-- | assert in `Either` monad, using `Left` to raise error+assert :: Bool -> a -> Either a ()+assert condition msg = unless condition $ Left msg++-- | assert in `ExceptT` monad, using `throwE` to raise error+assertE :: Monad m => Bool -> a -> ExceptT a m ()+assertE condition msg = unless condition $ throwE msg++-- | assert in any monad, using `fail` to raise error+assertM :: Monad m => Bool -> String -> m ()+assertM condition msg = unless condition $ fail msg