packages feed

alternative-extra (empty) → 0.1.0.0

raw patch · 5 files changed

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

Dependencies added: base

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for alternative-extra++## 0.1.0.0  -- 2017-02-19++* First version. Mostly generalized functions for Monoids.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, Marcos Dumay de Medeiros++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Marcos Dumay de Medeiros nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ alternative-extra.cabal view
@@ -0,0 +1,34 @@+-- Initial alternative-extra.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                alternative-extra+version:             0.1.0.0+synopsis:            Extra utilities for alternatives+description:         Extra utilities for alternatives+license:             BSD3+license-file:        LICENSE+author:              Marcos Dumay de Medeiros+maintainer:          marcos@marcosdumay.com+-- copyright:           +category:            Control+build-type:          Simple+extra-source-files:  ChangeLog.md+cabal-version:       >=1.10++source-repository head+  type:     git+  location: https://github.com/marcosdumay/alternative-extra.git+  branch:   master++source-repository this+  type:     git+  location: https://github.com/marcosdumay/alternative-extra.git+  tag:   0.1.0.0++library+  exposed-modules:     Control.AlternativeExtra+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >= 4 && <4.10+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Control/AlternativeExtra.hs view
@@ -0,0 +1,50 @@+{- |+Utilities extending Control.Applicative+-}+module Control.AlternativeExtra (+  mmany,+  msome,+  manyWith,+  someWith,+  ($<)+  )where++import Control.Applicative++-- | Many generalization for Monoid instances+mmany :: (Alternative a, Monoid m) => a m -> a m+mmany f = foldl mappend mempty <$> many f++-- | Some generatlization for Monoid instances+msome :: (Alternative a, Monoid m) => a m -> a m+msome f = foldl mappend mempty <$> some f++-- | Function application with lifted parameter+($<) :: Applicative m => m (a -> b) -> a -> m b+($<) f a = f <*> pure a++{- |++Utility for casting bare values into a Monoid in mmany.++For example, the function:++>  let sumMany = manyWith Sum getSum++will sum the results of many.+-}+manyWith :: (Alternative a, Monoid m) => (v -> m) -> (m -> v) -> a v -> a v+manyWith toMonoid fromMonoid f = fromMonoid <$> (mmany $ toMonoid <$> f)++{- |++Utility for casting bare values into a Monoid in msome.++For example, the function:++> let sumSome = someWith Sum getSum++will sum the results of some.+-}+someWith :: (Alternative a, Monoid m) => (v -> m) -> (m -> v) -> a v -> a v+someWith toMonoid fromMonoid f = fromMonoid <$> (msome $ toMonoid <$> f)