data-extra (empty) → 1.0.0
raw patch · 5 files changed
+95/−0 lines, 5 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- data-extra.cabal +18/−0
- src/Data/Either/Extra.hs +35/−0
- src/Data/Maybe/Extra.hs +10/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Chris Done++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Chris Done nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ data-extra.cabal view
@@ -0,0 +1,18 @@+name: data-extra+version: 1.0.0+synopsis: Extra utilities for working on Data.* types.+description: Extra utilities for working on Data.* types.+license: BSD3+license-file: LICENSE+author: Chris Done+maintainer: chrisdone@gmail.com+copyright: 2013 Chris Done+category: Data+build-type: Simple+cabal-version: >=1.8++library+ exposed-modules: Data.Either.Extra, Data.Maybe.Extra+ hs-source-dirs: src/+ build-depends: base > 4 && <5+ ghc-options: -Wall
+ src/Data/Either/Extra.hs view
@@ -0,0 +1,35 @@+-- | Extra functions for dealing with Either.++module Data.Either.Extra where++-- | A map for Either values.+mapEither :: (a -> b1) -> (b -> b2) -> Either a b -> Either b1 b2+mapEither l r = either (Left . l) (Right . r)++-- | Maybe get the left side of an Either.+leftToMaybe :: Either a b -> Maybe a+leftToMaybe = either Just (const Nothing)++-- | Maybe get the right side of an Either.+rightToMaybe :: Either a b -> Maybe b+rightToMaybe = either (const Nothing) Just++-- | Is a value Left?+isLeft :: Either a b -> Bool+isLeft (Left _) = True+isLeft (Right _) = False++-- | Is a value Right?+isRight :: Either a b -> Bool+isRight (Left _) = False+isRight (Right _) = True++-- | Extract the left value or a default.+fromLeft :: a -> Either a b -> a+fromLeft _ (Left x) = x+fromLeft x _ = x++-- | Extract the right value or a default.+fromRight :: b -> Either a b -> b+fromRight _ (Right x) = x+fromRight x _ = x
+ src/Data/Maybe/Extra.hs view
@@ -0,0 +1,10 @@+-- | Extra functions for dealing with Maybe.++module Data.Maybe.Extra where++import Control.Monad++-- | When the predicate is true, return maybe the action's return value.+whenMaybe :: Monad m => Bool -> m a -> m (Maybe a)+whenMaybe False _ = return Nothing+whenMaybe True m = liftM Just m