relude-0.6.0.0: Custom prelude from Kowainik
Copyright(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.Tuple

Description

Contains utility functions for working with tuples.

Synopsis

Documentation

dup :: a -> (a, a) Source #

Creates a tuple by pairing something with itself.

>>> dup "foo"
("foo","foo")
>>> dup ()
((),())

Since: 0.6.0.0

dupe :: a -> (a, a) Source #

Deprecated: Use dup instead, it has more idiomatic and common name

See dup.

mapToFst :: (a -> b) -> a -> (b, a) Source #

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

A dual to mapToSnd

>>> mapToFst (+1) 10
(11,10)

mapToSnd :: (a -> b) -> a -> (a, b) Source #

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

A dual to mapToFst.

>>> mapToSnd (+1) 10
(10,11)

mapBoth :: (a -> b) -> (a, a) -> (b, b) Source #

Deprecated: Use bimapBoth from Relude.Extra.Bifunctor instead

Maps a function over both elements of a tuple.

>>> mapBoth ("Hello " <>) ("Alice", "Bob")
("Hello Alice","Hello Bob")

traverseToFst :: Functor t => (a -> t b) -> a -> t (b, a) Source #

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

>>> traverseToFst (Just . (+1)) 10
Just (11,10)
>>> traverseToFst (const Nothing) 10
Nothing

traverseToSnd :: Functor t => (a -> t b) -> a -> t (a, b) Source #

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.

>>> traverseToSnd (Just . (+1)) 10
Just (10,11)
>>> traverseToSnd (const Nothing) 10
Nothing

traverseBoth :: Applicative t => (a -> t b) -> (a, a) -> t (b, b) Source #

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.

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