HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerelude-1.2.0.0Haskell2010

Relude.Extra.Tuple

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Contains utility functions for working with tuples.

  • 10 values
  • Packagerelude-1.2.0.0
  • Exports10
  • LanguageHaskell2010
  • LicenceMIT
  • SourceTuple.hs
valuedup :: a -> (a, a)
#

Creates a tuple by pairing something with itself.

Example2 expressions
dup "foo"("foo","foo")dup ()((),())
valuetoFst :: (a -> b) -> a -> (b, a)
#

Apply a function, with the result in the fst slot, and the value in the other.

A dual to toSnd.

Example2 expressions
toFst length [3, 1, 0, 2](4,[3,1,0,2])toFst (+5) 10(15,10)
valuetoSnd :: (a -> b) -> a -> (a, b)
#

Apply a function, with the result in the snd slot, and the value in the other.

A dual to toFst.

Example2 expressions
toSnd length [3, 1, 0, 2]([3,1,0,2],4)toSnd (+5) 10(10,15)
valuefmapToFst :: Functor f => (a -> b) -> f a -> f (b, a)
#

Like fmap, but also keep the original value in the snd position.

A dual to fmapToSnd.

Example1 expression
fmapToFst show [3, 10, 2][("3",3),("10",10),("2",2)]
valuefmapToSnd :: Functor f => (a -> b) -> f a -> f (a, b)
#

Like fmap, but also keep the original value in the fst position.

A dual to fmapToFst.

Example1 expression
fmapToSnd show [3, 10, 2][(3,"3"),(10,"10"),(2,"2")]
valuemapToFst :: (a -> b) -> a -> (b, a)
#

Deprecated. Use toFst from Relude.Extra.Tuple instead

Apply a function, with the result in the fst slot, and the value in the other.

A dual to mapToSnd

Example1 expression
mapToFst (+1) 10(11,10)
valuemapToSnd :: (a -> b) -> a -> (a, b)
#

Deprecated. Use toSnd from Relude.Extra.Tuple instead

Apply a function, with the result in the second slot, and the value in the other.

A dual to mapToFst.

Example1 expression
mapToSnd (+1) 10(10,11)
valuetraverseToFst :: Functor t => (a -> t b) -> a -> t (b, a)
#

Apply a function that returns a value inside of a functor, with the output in the first slot, the input in the second, and the entire tuple inside the functor.

A dual to traverseToSnd

Example2 expressions
traverseToFst (Just . (+1)) 10Just (11,10)traverseToFst (const Nothing) 10Nothing
valuetraverseToSnd :: Functor t => (a -> t b) -> a -> t (a, b)
#

Apply a function that returns a value inside of a functor, with the output in the second slot, the input in the first, and the entire tuple inside the functor.

A dual to traverseToFst.

Example2 expressions
traverseToSnd (Just . (+1)) 10Just (10,11)traverseToSnd (const Nothing) 10Nothing
valuetraverseBoth :: Applicative t => (a -> t b) -> (a, a) -> t (b, b)
#

Maps a function that returns a value inside of an applicative functor over both elements of a tuple, with the entire tuple inside the applicative functor.

Example2 expressions
traverseBoth (Just . ("Hello " <>)) ("Alice", "Bob")Just ("Hello Alice","Hello Bob")traverseBoth (const Nothing) ("Alice", "Bob")Nothing