Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Tuple.Extra
Description
Extra functions for working with pairs and triples. Some of these functions are available in the Control.Arrow module, but here are available specialised to pairs. Some operations work on triples.
Synopsis
- curry :: ((a, b) -> c) -> a -> b -> c
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- uncurry :: (a -> b -> c) -> (a, b) -> c
- data Solo a where
- getSolo :: Solo a -> a
- swap :: (a, b) -> (b, a)
- first :: (a -> a') -> (a, b) -> (a', b)
- second :: (b -> b') -> (a, b) -> (a, b')
- (***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
- (&&&) :: (a -> b) -> (a -> c) -> a -> (b, c)
- dupe :: a -> (a, a)
- both :: (a -> b) -> (a, a) -> (b, b)
- firstM :: Functor m => (a -> m a') -> (a, b) -> m (a', b)
- secondM :: Functor m => (b -> m b') -> (a, b) -> m (a, b')
- fst3 :: (a, b, c) -> a
- snd3 :: (a, b, c) -> b
- thd3 :: (a, b, c) -> c
- first3 :: (a -> a') -> (a, b, c) -> (a', b, c)
- second3 :: (b -> b') -> (a, b, c) -> (a, b', c)
- third3 :: (c -> c') -> (a, b, c) -> (a, b, c')
- curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
- uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
Documentation
Constructors
MkSolo a |
Instances
MonadZip Solo | |||||
Foldable1 Solo | |||||
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => Solo m -> m foldMap1 :: Semigroup m => (a -> m) -> Solo a -> m foldMap1' :: Semigroup m => (a -> m) -> Solo a -> m toNonEmpty :: Solo a -> NonEmpty a maximum :: Ord a => Solo a -> a minimum :: Ord a => Solo a -> a foldrMap1 :: (a -> b) -> (a -> b -> b) -> Solo a -> b foldlMap1' :: (a -> b) -> (b -> a -> b) -> Solo a -> b foldlMap1 :: (a -> b) -> (b -> a -> b) -> Solo a -> b foldrMap1' :: (a -> b) -> (a -> b -> b) -> Solo a -> b | |||||
Eq1 Solo | |||||
Defined in Data.Functor.Classes | |||||
Ord1 Solo | |||||
Defined in Data.Functor.Classes Methods liftCompare :: (a -> b -> Ordering) -> Solo a -> Solo b -> Ordering | |||||
Read1 Solo | |||||
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Solo a) liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Solo a] liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Solo a) liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Solo a] | |||||
Show1 Solo | |||||
Defined in Data.Functor.Classes Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Solo a -> ShowS liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Solo a] -> ShowS | |||||
NFData1 Solo | |||||
Defined in Control.DeepSeq | |||||
Applicative Solo | |||||
Functor Solo | |||||
Monad Solo | |||||
Foldable Solo | |||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => Solo m -> m # foldMap :: Monoid m => (a -> m) -> Solo a -> m # foldMap' :: Monoid m => (a -> m) -> Solo a -> m # foldr :: (a -> b -> b) -> b -> Solo a -> b # foldr' :: (a -> b -> b) -> b -> Solo a -> b # foldl :: (b -> a -> b) -> b -> Solo a -> b # foldl' :: (b -> a -> b) -> b -> Solo a -> b # foldr1 :: (a -> a -> a) -> Solo a -> a # foldl1 :: (a -> a -> a) -> Solo a -> a # elem :: Eq a => a -> Solo a -> Bool # maximum :: Ord a => Solo a -> a # | |||||
Traversable Solo | |||||
Generic1 Solo | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
NFData a => NFData (Solo a) | |||||
Defined in Control.DeepSeq | |||||
Monoid a => Monoid (Solo a) | |||||
Semigroup a => Semigroup (Solo a) | |||||
Bounded a => Bounded (Solo a) | |||||
Defined in GHC.Internal.Enum | |||||
Enum a => Enum (Solo a) | |||||
Defined in GHC.Internal.Enum | |||||
Generic (Solo a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Read a => Read (Solo a) | |||||
Show a => Show (Solo a) | |||||
Eq a => Eq (Solo a) | |||||
Ord a => Ord (Solo a) | |||||
type Rep1 Solo | |||||
Defined in GHC.Internal.Generics type Rep1 Solo = D1 ('MetaData "Solo" "GHC.Tuple" "ghc-prim" 'False) (C1 ('MetaCons "MkSolo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1)) | |||||
type Rep (Solo a) | |||||
Defined in GHC.Internal.Generics type Rep (Solo a) = D1 ('MetaData "Solo" "GHC.Tuple" "ghc-prim" 'False) (C1 ('MetaCons "MkSolo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) |
Specialised Arrow
functions
first :: (a -> a') -> (a, b) -> (a', b) Source #
Update the first component of a pair.
first succ (1,"test") == (2,"test")
second :: (b -> b') -> (a, b) -> (a, b') Source #
Update the second component of a pair.
second reverse (1,"test") == (1,"tset")
(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') infixr 3 Source #
Given two functions, apply one to the first component and one to the second.
A specialised version of ***
.
(succ *** reverse) (1,"test") == (2,"tset")
(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c) infixr 3 Source #
Given two functions, apply both to a single argument to form a pair.
A specialised version of &&&
.
(succ &&& pred) 1 == (2,0)
More pair operations
both :: (a -> b) -> (a, a) -> (b, b) Source #
Apply a single function to both components of a pair.
both succ (1,2) == (2,3)
Monadic versions
firstM :: Functor m => (a -> m a') -> (a, b) -> m (a', b) Source #
Update the first component of a pair.
firstM (\x -> [x-1, x+1]) (1,"test") == [(0,"test"),(2,"test")]
secondM :: Functor m => (b -> m b') -> (a, b) -> m (a, b') Source #
Update the second component of a pair.
secondM (\x -> [reverse x, x]) (1,"test") == [(1,"tset"),(1,"test")]
Operations on triple
first3 :: (a -> a') -> (a, b, c) -> (a', b, c) Source #
Update the first component of a triple.
first3 succ (1,1,1) == (2,1,1)
second3 :: (b -> b') -> (a, b, c) -> (a, b', c) Source #
Update the second component of a triple.
second3 succ (1,1,1) == (1,2,1)
third3 :: (c -> c') -> (a, b, c) -> (a, b, c') Source #
Update the third component of a triple.
third3 succ (1,1,1) == (1,1,2)