Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- any (>3) [1,2,3,4,5]
- any and[(>3),(<5)] [1,2,3,4,5]
- all or[(<2),(>4)] [1,2,3,4,5]
- any (x -> x > 3 && x < 5) [1..5]
- any (x -> x < 2 || x > 4) [1..5]
- infixr 3 &&&
- infixr 3 |||
- (&&&) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
- (f &&& g) x = f x && g x
- (|||) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
- (f ||| g) x = f x || g x
- any ((>3) &&& (<5)) [1..5]
- any ((<2) ||| (>4)) [1..5]
- andP :: [a -> Bool] -> a -> Bool
- andP ps x = all ($ x) ps
- andP [(>3), (<5)] x = x > 3 && x < 5
- any (andP [(>3), (<5)]) [1,2,3,4,5]
- between :: (Ord a) => a -> a -> a -> Bool
- between lo hi x = lo < x && x < hi
- any (between 3 5) [1,2,3,4,5]
- > import Data.Monoid
- > getAll $ mconcat [All True, All True, All False]
- False
- > getAll $ mconcat [All True, All True, All True]
- True
- > getAny $ mconcat [Any True, Any True, Any False]
- True
- instance Monoid b => Monoid (a -> b) where
- mempty _ = mempty
- mappend f g x = f x `mappend` g x
- > :t All
- All :: Bool -> All
- > :t (<5)
- (<5) :: (Num a, Ord a) => a -> Bool
- > :t All . (<5)
- All . (<5) :: (Num a, Ord a) => a -> All
- > :t ((All . (<5)) <> (All . (>3)))
- ((All . (<5)) <> (All . (>3))) :: (Num a, Ord a) => a -> All
- > getAll $ ((All . (<5)) <> (All . (>3))) 4
- True
- > getAll $ mconcat [(All. (<5)), (All . (>3))] $ 4
- True
- > getAll $ mconcat (map (All .) [(<5), (>3)]) $ 4
- True
- > import Data.Foldable
- > getAll $ foldMap (All .) [(<5), (>3)] $ 4
- True
- > map (getAll . foldMap (All .) [(<5), (>3)]) $ [1..5]
- [False,False,False,True,False]
- > Prelude.or $ map (getAll . foldMap (All .) [(<5), (>3)]) $ [1..5]
- True
- test = any (andP [(>3),(<5)]) [1,2,3,4,5]
- andP :: [a -> Bool] -> a -> Bool
- andP ps = getAll . mconcat (map (All.) ps)
Add Comment
Please, Sign In to add comment