packages feed

interspersed (empty) → 0.1.0.1

raw patch · 5 files changed

+162/−0 lines, 5 filesdep +base-preludedep +transformerssetup-changed

Dependencies added: base-prelude, transformers

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, 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
+ interspersed.cabal view
@@ -0,0 +1,51 @@+name:+  interspersed+version:+  0.1.0.1+synopsis:+  An abstraction over interspersing monadic actions+description:+category:+  Control+homepage:+  https://github.com/nikita-volkov/interspersed +bug-reports:+  https://github.com/nikita-volkov/interspersed/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2016, 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/interspersed.git+++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, 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:+    Interspersed.Prelude+  exposed-modules:+    Interspersed+  build-depends:+    -- +    transformers >= 0.4 && < 0.6,+    base-prelude < 2
+ library/Interspersed.hs view
@@ -0,0 +1,43 @@+module Interspersed+(+  Interspersed,+  runInterspersed,+  interspersed,+)+where++import Interspersed.Prelude+++-- |+-- An abstraction over interspersing monadic actions.+newtype Interspersed m a =+  Interspersed (ReaderT (m ()) (StateT Bool m) a)+  deriving (Functor, Applicative, Alternative, Monad, MonadPlus)++instance MonadTrans Interspersed where+  {-# INLINE lift #-}+  lift =+    interspersed++{-# INLINE runInterspersed #-}+runInterspersed :: Monad m => Interspersed m a -> m () -> m a+runInterspersed (Interspersed impl) sep =+  {-# SCC "runInterspersed" #-} +  flip evalStateT True $+  flip runReaderT sep $+  impl++-- |+-- Lifts a monadic action. Same as 'lift'.+{-# INLINABLE interspersed #-}+interspersed :: Applicative m => m a -> Interspersed m a+interspersed fx =+  {-# SCC "interspersed" #-} +  Interspersed $+  ReaderT $+  \sep ->+    StateT $+    \first ->+      fmap (\a -> (a, False)) $+      unless first sep *> fx
+ library/Interspersed/Prelude.hs view
@@ -0,0 +1,44 @@+module Interspersed.Prelude+( +  module Exports,+  modifyM,+  skipSepBy,+  skipSepBy1,+)+where+++-- base-prelude+-------------------------+import BasePrelude as Exports hiding (Alt, scanl)++-- transformers+-------------------------+import Control.Monad.IO.Class as Exports+import Control.Monad.Trans.Class as Exports+import Control.Monad.Trans.Except as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)+import Control.Monad.Trans.Reader as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)+import Control.Monad.Trans.State.Strict as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)+import Control.Monad.Trans.Writer.Strict as Exports+import Control.Monad.Trans.Maybe as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)++-- Utils+-------------------------++{-# INLINE modifyM #-}+modifyM :: Monad m => (a -> m a) -> StateT a m ()+modifyM f =+  StateT (fmap (\s -> ((), s)) . f)++{-# INLINE skipSepBy #-}+skipSepBy :: Alternative m => m () -> m () -> m ()+skipSepBy one sep =+  skipSepBy1 one sep <|> pure ()++{-# INLINABLE skipSepBy1 #-}+skipSepBy1 :: Alternative m => m () -> m () -> m ()+skipSepBy1 one sep =+  one *> remainders+  where+    remainders =+      (sep *> one *> remainders) <|> pure ()