ringo/ringo/src/Ringo/Utils.hs

56 lines
1021 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Ringo.Utils where
import qualified Control.Arrow as Arrow
import Prelude.Compat
import Data.Maybe (mapMaybe)
for :: [a] -> (a -> b) -> [b]
for = flip map
forMaybe :: [a] -> (a -> Maybe b) -> [b]
forMaybe = flip mapMaybe
concatFor :: (Foldable t) => t a -> (a -> [b]) -> [b]
concatFor = flip concatMap
infixr 3 ***, &&&
first :: (a -> a') -> (a, b) -> (a', b)
first = Arrow.first
second :: (b -> b') -> (a, b) -> (a, b')
second = Arrow.second
(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
(***) = (Arrow.***)
(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c)
(&&&) = (Arrow.&&&)
(>>>) :: (a -> b) -> (b -> c) -> (a -> c)
(>>>) = (Arrow.>>>)
(>>-) :: a -> (a -> b) -> b
(>>-) v f = f v
infixr 1 >>-
dupe :: a -> (a,a)
dupe x = (x, x)
both :: (a -> b) -> (a, a) -> (b, b)
both f (x, y) = (f x, f y)
fst3 :: (a, b, c) -> a
fst3 (a, _, _) = a
snd3 :: (a, b, c) -> b
snd3 (_, b, _) = b
thd3 :: (a, b, c) -> c
thd3 (_, _, c) = c