filtrable (empty) → 0.1.0.0
raw patch · 4 files changed
+60/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- Data/Filtrable.hs +39/−0
- LICENSE +5/−0
- Setup.hs +2/−0
- filtrable.cabal +14/−0
+ Data/Filtrable.hs view
@@ -0,0 +1,39 @@+module Data.Filtrable where++import Prelude hiding (filter)++import Control.Applicative+import Control.Monad+import Data.Proxy+import Data.Traversable++class Functor f => Filtrable f where+ {-# MINIMAL mapMaybe | catMaybes #-}++ mapMaybe :: (a -> Maybe b) -> f a -> f b+ mapMaybe f = catMaybes . fmap f++ catMaybes :: f (Maybe a) -> f a+ catMaybes = mapMaybe id++ filter :: (a -> Bool) -> f a -> f a+ filter f = mapMaybe (liftA2 (<$) id (guard . f))++instance Filtrable [] where+ mapMaybe f = foldr (maybe id (:) . f) []++instance Filtrable Maybe where+ mapMaybe = (=<<)+ catMaybes = join++instance Filtrable Proxy where+ mapMaybe _ Proxy = Proxy++instance Filtrable (Const a) where+ mapMaybe _ (Const x) = Const x++mapMaybeA :: (Filtrable f, Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b)+mapMaybeA f xs = catMaybes <$> traverse f xs++filterA :: (Filtrable f, Traversable f, Applicative p) => (a -> p Bool) -> f a -> p (f a)+filterA f = mapMaybeA (\ x -> (x <$) . guard <$> f x)
+ LICENSE view
@@ -0,0 +1,5 @@+© Unix year 45 (Strake = M Farkas-Dyck)++Leave to use, copy, modify, and distribute this work for any purpose is hereby granted if the above copyright notice and this license are included.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ filtrable.cabal view
@@ -0,0 +1,14 @@+name: filtrable+version: 0.1.0.0+synopsis: Class of filtrable containers+license: OtherLicense+license-file: LICENSE+author: M Farkas-Dyck+maintainer: strake888@gmail.com+category: Data+build-type: Simple+cabal-version: >=1.9.2++library+ exposed-modules: Data.Filtrable+ build-depends: base >=4.8 && <4.9