mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-19 01:39:32 -06:00
Some changed/new utility functions
GF.Data.Utilities: Rename mapFst to apFst, mapSnd to apSnd. Add apBoth, mapFst, mapSnd, mapBoth. GF.Data.Operations: Remove onSnd (same as apSnd)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module GF.Data.Operations (-- * misc functions
|
||||
ifNull, onSnd,
|
||||
ifNull,
|
||||
|
||||
-- * the Error monad
|
||||
Err(..), err, maybeErr, testErr, errVal, errIn,
|
||||
@@ -76,9 +76,6 @@ infixr 5 +++++
|
||||
ifNull :: b -> ([a] -> b) -> [a] -> b
|
||||
ifNull b f xs = if null xs then b else f xs
|
||||
|
||||
onSnd :: (a -> b) -> (c,a) -> (c,b)
|
||||
onSnd f (x, y) = (x, f y)
|
||||
|
||||
-- the Error monad
|
||||
|
||||
-- | analogue of @maybe@
|
||||
|
||||
@@ -130,11 +130,20 @@ both f g x y = g (f x) (f y)
|
||||
|
||||
-- * functions on pairs
|
||||
|
||||
mapFst :: (a -> a') -> (a, b) -> (a', b)
|
||||
mapFst f (a, b) = (f a, b)
|
||||
apFst :: (a -> a') -> (a, b) -> (a', b)
|
||||
apFst f (a, b) = (f a, b)
|
||||
|
||||
mapSnd :: (b -> b') -> (a, b) -> (a, b')
|
||||
mapSnd f (a, b) = (a, f b)
|
||||
apSnd :: (b -> b') -> (a, b) -> (a, b')
|
||||
apSnd f (a, b) = (a, f b)
|
||||
|
||||
apBoth :: (a -> b) -> (a, a) -> (b, b)
|
||||
apBoth f (x, y) = (f x, f y)
|
||||
|
||||
-- * functions on lists of pairs
|
||||
|
||||
mapFst = map . apFst
|
||||
mapSnd = map . apSnd
|
||||
mapBoth = map . apBoth
|
||||
|
||||
-- * functions on monads
|
||||
|
||||
|
||||
Reference in New Issue
Block a user