packages feed

matcher (empty) → 0.1.1.2

raw patch · 5 files changed

+224/−0 lines, 5 filesdep +base-preludedep +profunctorsdep +successsetup-changed

Dependencies added: base-prelude, profunctors, success, text, transformers

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, Sannsyn AS++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/Matcher.hs view
@@ -0,0 +1,115 @@+module Matcher+(+  Matcher,+  run,+  equals,+  satisfies,+  converts,+  whatever,+)+where++import Matcher.Prelude+import qualified Success.Pure+++-- |+-- Converts the matcher into a conversion function,+-- which results in either a successful result or a failure.+{-# INLINABLE run #-}+run :: Matcher a b -> a -> Either Text b+run (Matcher (ReaderT successFn)) input =+  {-# SCC "run" #-} +  either (Left . fromMaybe "") Right $+  Success.Pure.asEither $+  successFn input+++-- |+-- A composable abstraction for checking or converting a context value.+newtype Matcher a b =+  Matcher (ReaderT a (Success Text) b)+  deriving (Functor, Applicative, Alternative, Monad, MonadPlus)++instance Profunctor Matcher where+  {-# INLINE lmap #-}+  lmap fn (Matcher (ReaderT successFn)) =+    Matcher (ReaderT (successFn . fn))+  {-# INLINE rmap #-}+  rmap =+    fmap++instance Category Matcher where+  {-# INLINE id #-}+  id =+    Matcher $+    ReaderT $+    Success.Pure.success+  {-# INLINE (.) #-}+  (.) (Matcher (ReaderT successFn2)) (Matcher (ReaderT successFn1)) =+    Matcher $+    ReaderT $+    successFn1 >=> successFn2++instance Arrow Matcher where+  {-# INLINE arr #-}+  arr f =+    Matcher $+    ReaderT $+    Success.Pure.success . f+  {-# INLINE first #-}+  first (Matcher (ReaderT successFn)) =+    Matcher $+    ReaderT $+    \(a, b) ->+      fmap (\a -> (a, b)) $+      successFn a+++-- |+-- Tests the matched value on equality with the provided value.+{-# INLINE equals #-}+equals :: Eq a => a -> Matcher a ()+equals reference =+  {-# SCC "equals" #-} +  Matcher $+  ReaderT $+  \input ->+    if input == reference+      then Success.Pure.success ()+      else Success.Pure.failure "The input doesn't equal the expected value"++-- |+-- Checks whether the matched value satisfies the provided predicate.+{-# INLINE satisfies #-}+satisfies :: (a -> Bool) -> Matcher a ()+satisfies predicate =+  {-# SCC "satisfies" #-} +  Matcher $+  ReaderT $+  \input ->+    if predicate input+      then Success.Pure.success ()+      else Success.Pure.failure "The input doesn't satisfy the predicate"++-- |+-- Tries to convert the matched value to an output value,+-- with 'Either' encoding the success or failure of the conversion.+{-# INLINE converts #-}+converts :: (a -> Either Text b) -> Matcher a b+converts match =+  {-# SCC "converts" #-} +  Matcher $+  ReaderT $+  either Success.Pure.failure Success.Pure.success . match++-- |+-- The matcher, which is always satisfied.+{-# INLINE whatever #-}+whatever :: Matcher a ()+whatever =+  {-# SCC "whatever" #-} +  Matcher $+  ReaderT $+  const $+  pure ()
+ library/Matcher/Prelude.hs view
@@ -0,0 +1,32 @@+module Matcher.Prelude +(+  module Exports,+)+where++-- base-prelude+-------------------------+import BasePrelude as Exports++-- transformers+-------------------------+import Control.Monad.IO.Class as Exports+import Control.Monad.Trans.Class as Exports+import Control.Monad.Trans.Cont as Exports hiding (shift, callCC)+import Control.Monad.Trans.Except as Exports (ExceptT(ExceptT), Except, except, runExcept, runExceptT, mapExcept, mapExceptT, withExcept, withExceptT)+import Control.Monad.Trans.Maybe as Exports+import Control.Monad.Trans.Reader as Exports (Reader, runReader, mapReader, withReader, ReaderT(ReaderT), runReaderT, mapReaderT, withReaderT)+import Control.Monad.Trans.State.Strict as Exports (State, runState, evalState, execState, mapState, withState, StateT(StateT), runStateT, evalStateT, execStateT, mapStateT, withStateT)+import Control.Monad.Trans.Writer.Strict as Exports (Writer, runWriter, execWriter, mapWriter, WriterT(..), execWriterT, mapWriterT)++-- profunctors+-------------------------+import Data.Profunctor.Unsafe as Exports++-- success+-------------------------+import Success.Pure as Exports (Success)++-- text+-------------------------+import Data.Text as Exports (Text)
+ matcher.cabal view
@@ -0,0 +1,53 @@+name:+  matcher+version:+  0.1.1.2+synopsis:+  A composable abstraction for checking or converting a context value+homepage:+  https://github.com/sannsyn/matcher+bug-reports:+  https://github.com/sannsyn/matcher/issues+author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2016, Sannsyn AS+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.10+++source-repository head+  type:+    git+  location:+    git://github.com/sannsyn/matcher.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+  other-modules:+    Matcher.Prelude+  exposed-modules:+    Matcher+  build-depends:+    -- data:+    text >= 1 && < 2,+    -- general:+    success >= 0.2.6 && < 0.3,+    profunctors >= 5.2 && < 6,+    transformers >= 0.3 && < 0.6,+    base-prelude < 2+