make-monofoldable-foldable (empty) → 0.1.0.0
raw patch · 4 files changed
+101/−0 lines, 4 filesdep +basedep +mono-traversablesetup-changed
Dependencies added: base, mono-traversable
Files
- LICENSE +19/−0
- Setup.hs +2/−0
- make-monofoldable-foldable.cabal +26/−0
- src/Data/MonoTraversable/WrapMonoFoldable.hs +54/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright 2017 Clinton Mead++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
+ make-monofoldable-foldable.cabal view
@@ -0,0 +1,26 @@+name: make-monofoldable-foldable+version: 0.1.0.0+synopsis: Make a MonoFoldable type into an ordinary Foldable type.+description:+ For a container to be "Foldable", it must be able to accept all types. This means that ByteStrings and unboxed arrays/vectors+ are not foldable, as they have restrictions on their elements. This wrapper makes them Foldable.+license: MIT+license-file: LICENSE+homepage: +author: Clinton Mead+maintainer: clintonmead@gmail.com+category: Data+build-type: Simple+cabal-version: >=1.10+tested-with: GHC == 8.0.2+bug-reports: https://github.com/clintonmead/make-monofoldable-foldable/issues++source-repository head+ type: git+ location: https://github.com/clintonmead/make-monofoldable-foldable.git++library+ exposed-modules: Data.MonoTraversable.WrapMonoFoldable+ build-depends: base == 4.9.*, mono-traversable == 1.0.*+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Data/MonoTraversable/WrapMonoFoldable.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE GADTs #-}++module Data.MonoTraversable.WrapMonoFoldable (+ WrappedMonoFoldable(WrappedMonoFoldable),+ wrapMonoFoldable+ )+ where++import Data.Foldable (+ Foldable,+ fold,+ foldMap,+ foldr,+ foldl',+ foldr1,+ foldl1,+ toList,+ null,+ length,+ elem,+ maximum,+ minimum,+ sum,+ product+ )++import Data.MonoTraversable (+ MonoFoldable,+ Element+ )++import qualified Data.MonoTraversable.Unprefixed as MF++{-|+Turns any 'MonoFoldable' into a 'Foldable' type.+-}+data WrappedMonoFoldable mono element where+ WrappedMonoFoldable :: (MonoFoldable mono) => mono -> WrappedMonoFoldable mono (Element mono)++instance Foldable (WrappedMonoFoldable mono) where+ fold (WrappedMonoFoldable y) = MF.fold y+ foldMap x1 (WrappedMonoFoldable y) = MF.foldMap x1 y+ foldr x1 x2 (WrappedMonoFoldable y) = MF.foldr x1 x2 y+ foldl' x1 x2 (WrappedMonoFoldable y) = MF.foldl' x1 x2 y+ toList (WrappedMonoFoldable y) = MF.toList y+ null (WrappedMonoFoldable y) = MF.null y+ length (WrappedMonoFoldable y) = MF.length y+ elem x1 (WrappedMonoFoldable y) = MF.elem x1 y+ sum (WrappedMonoFoldable y) = MF.sum y+ product (WrappedMonoFoldable y) = MF.product y++wrapMonoFoldable :: (MonoFoldable mono) => mono -> WrappedMonoFoldable mono (Element mono)+wrapMonoFoldable = WrappedMonoFoldable