packages feed

success (empty) → 0.2

raw patch · 5 files changed

+224/−0 lines, 5 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2015, Nikita Volkov++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
+ library/Success/Impure.hs view
@@ -0,0 +1,78 @@+-- |+-- The types and functions are trivial and self-descriptive,+-- hence this sentence is the sole documentation you get on them.+module Success.Impure+(+  Success(..),+  run,+  nothing, failure, success,+)+where++import Prelude+import Control.Applicative+import Control.Monad+import qualified Success.Pure+++newtype Success a m b =+  Success (m (Success.Pure.Success a b))+  deriving (Functor)++instance Applicative m => Applicative (Success e m) where+  {-# INLINE pure #-}+  pure a =+    Success (pure (Success.Pure.success a))+  {-# INLINE (<*>) #-}+  (<*>) (Success m1) (Success m2) =+    Success ((liftA2 . liftA2) ($) m1 m2)++instance Applicative m => Alternative (Success e m) where+  {-# INLINE empty #-}+  empty =+    Success (pure Success.Pure.nothing)+  {-# INLINE (<|>) #-}+  (<|>) (Success m1) (Success m2) =+    Success (liftA2 (<|>) m1 m2)++instance Monad m => Monad (Success e m) where+  {-# INLINE return #-}+  return =+    pure+  {-# INLINABLE (>>=) #-}+  (>>=) m1 m2' =+    Success (run m1 >>= m2 . Success.Pure.asEither)+    where+      m2 =+        \case+          Left Nothing -> pure Success.Pure.nothing+          Left (Just e) -> pure (Success.Pure.failure e)+          Right x -> run (m2' x)++instance Monad m => MonadPlus (Success e m) where+  {-# INLINE mzero #-}+  mzero =+    empty+  {-# INLINE mplus #-}+  mplus =+    (<|>)++{-# INLINE run #-}+run :: Success e m a -> m (Success.Pure.Success e a)+run (Success m) =+  m++{-# INLINE nothing #-}+nothing :: Applicative m => Success e m a+nothing =+  Success (pure Success.Pure.nothing)++{-# INLINE failure #-}+failure :: Applicative m => e -> Success e m a+failure details =+  Success (pure (Success.Pure.failure details))++{-# INLINE success #-}+success :: Applicative m => a -> Success e m a+success value =+  Success (pure (Success.Pure.success value))
+ library/Success/Pure.hs view
@@ -0,0 +1,69 @@+-- |+-- The types and functions are trivial and self-descriptive,+-- hence this sentence is the sole documentation you get on them.+module Success.Pure+(+  Success,+  -- * Creation+  nothing,+  failure,+  success,+  -- * Execution+  asEither,+  asMaybe,+)+where++import Prelude+import Control.Applicative+import Control.Monad+++newtype Success a b =+  Success (Either (Maybe a) b)+  deriving (Functor, Applicative, Monad)++instance Alternative (Success a) where+  {-# INLINE empty #-}+  empty =+    Success (Left Nothing)+  {-# INLINE (<|>) #-}+  (<|>) =+    \case+      Success (Right x) -> const (Success (Right x))+      Success (Left _) -> id++instance MonadPlus (Success a) where+  {-# INLINE mzero #-}+  mzero =+    empty+  {-# INLINE mplus #-}+  mplus =+    (<|>)++{-# INLINE nothing #-}+nothing :: Success a b+nothing =+  Success (Left Nothing)++{-# INLINE failure #-}+failure :: a -> Success a b+failure failure =+  Success (Left (Just failure))++{-# INLINE success #-}+success :: b -> Success a b+success =+  pure++{-# INLINE asEither #-}+asEither :: Success a b -> Either (Maybe a) b+asEither (Success x) =+  x++{-# INLINE asMaybe #-}+asMaybe :: Success a b -> Maybe b+asMaybe (Success x) =+  case x of+    Left _ -> Nothing+    Right x -> Just x
+ success.cabal view
@@ -0,0 +1,53 @@+name:+  success+version:+  0.2+synopsis:+  A version of Either specialised for encoding of success or failure+description:+  The primary motivation for creation of this package was the need+  for the 'Alternative' instance of 'Either',+  which there is no sane way to implement.+  The type provided by this library extends 'Either' in a way to provide the missing instance.+category:+  Data, Failure+homepage:+  https://github.com/nikita-volkov/success +bug-reports:+  https://github.com/nikita-volkov/success/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2015, Nikita Volkov+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.10+++source-repository head+  type:+    git+  location:+    git://github.com/nikita-volkov/success.git+++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFunctor, DeriveGeneric, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+  default-language:+    Haskell2010+  exposed-modules:+    Success.Pure+    Success.Impure+  build-depends:+    base >= 4.6 && < 5+