packages feed

transaction (empty) → 0.1.0.0

raw patch · 7 files changed

+231/−0 lines, 7 filesdep +Globdep +basedep +doctestsetup-changed

Dependencies added: Glob, base, doctest, semigroups, transaction

Files

+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2018 Kadzuya OKAMOTO, https://arow.info++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.
+ README.md view
@@ -0,0 +1,8 @@+[![Build Status](https://travis-ci.org/arowM/haskell-transaction.svg?branch=master)](https://travis-ci.org/arowM/haskell-transaction)+[![Hackage](https://img.shields.io/hackage/v/transaction.svg)](https://hackage.haskell.org/package/transaction)+[![Stackage LTS](http://stackage.org/package/transaction/badge/lts)](http://stackage.org/lts/package/transaction)+[![Stackage Nightly](http://stackage.org/package/transaction/badge/nightly)](http://stackage.org/nightly/package/transaction)++# Haskell-transaction++Monadic representation of transactions.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Transaction.hs view
@@ -0,0 +1,128 @@+{-# LANGUAGE DeriveFunctor #-}++{- |+Module      :  Data.Transaction++Copyright   :  Kadzuya Okamoto 2018+License     :  MIT++Stability   :  experimental+Portability :  unknown++Monadic representation of transactions.+-}+module Data.Transaction+  (+  -- * Constructors+  action++  -- * Converters+  , reduce+  , toList+  , tMap+  , tFilter+  , tFilterMap++  -- * Types+  , Transaction+  , TransactionM+  ) where++{- ==============+ -     Types+ - ============== -}++data TransactionM a x+  = TVal a (TransactionM a x)+  | TNull x+  deriving (Functor)++type Transaction a = TransactionM a ()++instance Applicative (TransactionM a) where+  pure = TNull+  TVal a next <*> f = TVal a (next <*> f)+  TNull g <*> f = f >>= (pure . g)++instance Monad (TransactionM a) where+  return = pure+  TVal a next >>= f = TVal a (next >>= f)+  TNull a >>= f = f a++{- ==============+ -   Operators+ - ============== -}++{- |+>>> :{+toList $ do+  action 4+  action 5+  action 6+:}+[4,5,6]+-}+action :: a -> Transaction a+action a = TVal a $ pure ()++{- ==============+ -   Converters+ - ============== -}++{- |+>>> :{+toList $ do+  action 4+  tMap (+1) $ do+    action 5+    action 6+  action 7+:}+[4,6,7,7]+-}+tMap :: (a -> b) -> Transaction a -> Transaction b+tMap f = tFilterMap (pure . f)++{- |+>>> :{+toList $ do+  action 4+  tFilter even $ do+    action 5+    action 6+  action 7+:}+[4,6,7]+-}+tFilter :: (a -> Bool) -> Transaction a -> Transaction a+tFilter p = tFilterMap $ \a ->+  if p a+    then Just a+    else Nothing++{- |+>>> :{+toList $ do+  action 4+  tFilterMap (\x -> if even x then Just (x + 1) else Nothing) $ do+    action 5+    action 6+  action 7+:}+[4,7,7]+-}+tFilterMap :: (a -> Maybe b) -> Transaction a -> Transaction b+tFilterMap f (TVal a next) =+  case f a of+    Just b ->+      TVal b $ tFilterMap f next+    Nothing ->+      tFilterMap f next+tFilterMap _ (TNull ()) = TNull ()++reduce :: (b -> a -> b) -> b -> Transaction a -> b+reduce f b (TVal a next) = reduce f (f b a) next+reduce _ b (TNull ()) = b++toList :: Transaction a -> [a]+toList trans = reduce (\f a -> f . (a:)) id trans []
+ test/Doctest.hs view
@@ -0,0 +1,19 @@+module Main where++import Data.Monoid ((<>))+import System.FilePath.Glob (glob)+import Test.DocTest (doctest)++main :: IO ()+main = glob "src/**/*.hs" >>= doDocTest++doDocTest :: [String] -> IO ()+doDocTest options = doctest $ options <> ghcExtensions++ghcExtensions :: [String]+ghcExtensions =+    [ "-XOverloadedStrings"+    , "-XRecordWildCards"+    , "-XStrict"+    , "-XStrictData"+    ]
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"
+ transaction.cabal view
@@ -0,0 +1,51 @@+name:                transaction+version:             0.1.0.0+synopsis:            Monadic representation of transactions.+description:+    Monadic representation of transactions.+homepage:            https://github.com/arowM/haskell-transaction#readme+license:             MIT+license-file:        LICENSE+author:              Kadzuya Okamoto+maintainer:          arow.okamoto+github@gmail.com+copyright:           2018 Kadzuya Okamoto+category:            Data+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Data.Transaction+  build-depends:       base >= 4.9 && < 5+  default-language:    Haskell2010+  default-extensions:  OverloadedStrings+                     , RecordWildCards+  other-extensions:    GeneralizedNewtypeDeriving+  ghc-options:         -Wcompat -Wall+  if !impl(ghc >= 8.0)+    build-depends: semigroups == 0.18.*++test-suite transaction-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , transaction+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++test-suite doctest+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Doctest.hs+  build-depends:       base+                     , Glob+                     , doctest >= 0.10+                     , transaction+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/arowM/haskell-transaction