packages feed

result (empty) → 0.1.0.0

raw patch · 5 files changed

+104/−0 lines, 5 filesdep +basedep +keysdep +resultsetup-changed

Dependencies added: base, keys, result, semigroups

Files

+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2016 Sam Rijs++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
+ result.cabal view
@@ -0,0 +1,34 @@+name:                result+version:             0.1.0.0+synopsis:            Encode success or at least one error+homepage:            https://github.com/srijs/haskell-result+license:             MIT+license-file:        LICENSE+author:              Sam Rijs+maintainer:          srijs@airpost.net+copyright:           2016 Sam Rijs+category:            Data+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Data.Result+  build-depends:       base >= 4 && < 5,+                       semigroups,+                       keys+  default-language:    Haskell2010++test-suite test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , result+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/srijs/haskell-result
+ src/Data/Result.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++module Data.Result where+++import Data.Monoid+import Data.Key+import qualified Data.List.NonEmpty as NonEmpty+++newtype Result e a =+    Result (Either (NonEmpty.NonEmpty e) a)+  deriving (Eq, Ord, Show, Functor, Applicative, Monad)+++instance Zip (Result e) where+  zipWith f mea meb =+    case (mea, meb) of+      (Result (Right eaa), Result (Right eba)) ->+        Result (Right (f eaa eba))+      _ ->+        Result (Left (NonEmpty.fromList (errors mea <> errors meb)))+++raise :: e -> Result e a+raise e =+  Result (Left (e NonEmpty.:| []))+++get :: Result e a -> Maybe a+get (Result e) =+  case e of+    Left _ ->+      Nothing+    Right a ->+      Just a+++errors :: Result e a -> [e]+errors (Result e) =+  case e of+    Left es ->+      NonEmpty.toList es+    Right _ ->+      []
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"