base-4.10.0.0: Basic libraries

Copyright (C) 2011-2016 Edward Kmett BSD-style (see the file LICENSE) libraries@haskell.org provisional portable Trustworthy Haskell2010

Data.Bitraversable

Description

Since: 4.10.0.0

Synopsis

# Documentation

class (Bifunctor t, Bifoldable t) => Bitraversable t where Source #

Bitraversable identifies bifunctorial data structures whose elements can be traversed in order, performing Applicative or Monad actions at each element, and collecting a result structure with the same shape.

As opposed to Traversable data structures, which have one variety of element on which an action can be performed, Bitraversable data structures have two such varieties of elements.

A definition of bitraverse must satisfy the following laws:

naturality
bitraverse (t . f) (t . g) ≡ t . bitraverse f g for every applicative transformation t
identity
bitraverse Identity Identity ≡ Identity
composition
Compose . fmap (bitraverse g1 g2) . bitraverse f1 f2 ≡ traverse (Compose . fmap g1 . f1) (Compose . fmap g2 . f2)

where an applicative transformation is a function

t :: (Applicative f, Applicative g) => f a -> g a

preserving the Applicative operations:

t (pure x) = pure x
t (f <*> x) = t f <*> t x


and the identity functor Identity and composition functors Compose are defined as

newtype Identity a = Identity { runIdentity :: a }

instance Functor Identity where
fmap f (Identity x) = Identity (f x)

instance Applicative Identity where
pure = Identity
Identity f <*> Identity x = Identity (f x)

newtype Compose f g a = Compose (f (g a))

instance (Functor f, Functor g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (fmap (fmap f) x)

instance (Applicative f, Applicative g) => Applicative (Compose f g) where
pure = Compose . pure . pure
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x) Some simple examples are Either and '(,)': instance Bitraversable Either where bitraverse f _ (Left x) = Left <$> f x
bitraverse _ g (Right y) = Right <$> g y instance Bitraversable (,) where bitraverse f g (x, y) = (,) <$> f x <*> g y

Bitraversable relates to its superclasses in the following ways:

bimap f g ≡ runIdentity . bitraverse (Identity . f) (Identity . g)
bifoldMap f g = getConst . bitraverse (Const . f) (Const . g)


These are available as bimapDefault and bifoldMapDefault respectively.

Since: 4.10.0.0

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> t a b -> f (t c d) Source #

Evaluates the relevant functions at each element in the structure, running the action, and builds a new structure with the same shape, using the results produced from sequencing the actions.

bitraverse f g ≡ bisequenceA . bimap f g

For a version that ignores the results, see bitraverse_.

Since: 4.10.0.0

Instances

 Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) Source # Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (a, b) -> f (c, d) Source # Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Arg a b -> f (Arg c d) Source # Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (x, a, b) -> f (x, c, d) Source # Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Const * a b -> f (Const * c d) Source # Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> K1 * i a b -> f (K1 * i c d) Source # Bitraversable ((,,,) x y) Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (x, y, a, b) -> f (x, y, c, d) Source # Bitraversable ((,,,,) x y z) Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (x, y, z, a, b) -> f (x, y, z, c, d) Source # Bitraversable ((,,,,,) x y z w) Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (x, y, z, w, a, b) -> f (x, y, z, w, c, d) Source # Bitraversable ((,,,,,,) x y z w v) Source # Since: 4.10.0.0 Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> (x, y, z, w, v, a, b) -> f (x, y, z, w, v, c, d) Source #

bisequenceA :: (Bitraversable t, Applicative f) => t (f a) (f b) -> f (t a b) Source #

Alias for bisequence.

Since: 4.10.0.0

bisequence :: (Bitraversable t, Applicative f) => t (f a) (f b) -> f (t a b) Source #

Sequences all the actions in a structure, building a new structure with the same shape using the results of the actions. For a version that ignores the results, see bisequence_.

bisequence ≡ bitraverse id id

Since: 4.10.0.0

bimapM :: (Bitraversable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f (t c d) Source #

Alias for bitraverse.

Since: 4.10.0.0

bifor :: (Bitraversable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f (t c d) Source #

bifor is bitraverse with the structure as the first argument. For a version that ignores the results, see bifor_.

Since: 4.10.0.0

biforM :: (Bitraversable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f (t c d) Source #

Alias for bifor.

Since: 4.10.0.0

bimapAccumL :: Bitraversable t => (a -> b -> (a, c)) -> (a -> d -> (a, e)) -> a -> t b d -> (a, t c e) Source #

The bimapAccumL function behaves like a combination of bimap and bifoldl; it traverses a structure from left to right, threading a state of type a and using the given actions to compute new elements for the structure.

Since: 4.10.0.0

bimapAccumR :: Bitraversable t => (a -> b -> (a, c)) -> (a -> d -> (a, e)) -> a -> t b d -> (a, t c e) Source #

The bimapAccumR function behaves like a combination of bimap and bifoldl; it traverses a structure from right to left, threading a state of type a and using the given actions to compute new elements for the structure.

Since: 4.10.0.0

bimapDefault :: forall t a b c d. Bitraversable t => (a -> b) -> (c -> d) -> t a c -> t b d Source #

A default definition of bimap in terms of the Bitraversable operations.

bimapDefault f g ≡
runIdentity . bitraverse (Identity . f) (Identity . g)

Since: 4.10.0.0

bifoldMapDefault :: forall t m a b. (Bitraversable t, Monoid m) => (a -> m) -> (b -> m) -> t a b -> m Source #

A default definition of bifoldMap in terms of the Bitraversable operations.

bifoldMapDefault f g ≡
getConst . bitraverse (Const . f) (Const . g)

Since: 4.10.0.0
{"ft_lang_label":"__label__en","ft_lang_prob":0.64356446,"math_prob":0.92972994,"size":7300,"snap":"2021-04-2021-17","text_gpt3_token_len":2578,"char_repetition_ratio":0.22998904,"word_repetition_ratio":0.47758153,"special_character_ratio":0.37356165,"punctuation_ratio":0.19935691,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9925882,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-13T01:54:33Z\",\"WARC-Record-ID\":\"<urn:uuid:b79b70fd-adea-44ef-87bc-779da8386f50>\",\"Content-Length\":\"30025\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5b9b10dd-44ed-4d34-ba67-08e88721b33f>\",\"WARC-Concurrent-To\":\"<urn:uuid:b9eb5e51-fa2e-4f94-83c6-677e6d49dd1d>\",\"WARC-IP-Address\":\"151.101.200.68\",\"WARC-Target-URI\":\"https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bitraversable.html\",\"WARC-Payload-Digest\":\"sha1:R3OAFH2THY62L6IMIKSFTSB73CTDIEXM\",\"WARC-Block-Digest\":\"sha1:NHZEUPTSPFGWIHPSXJUP4BW5FPTZBCNS\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038071212.27_warc_CC-MAIN-20210413000853-20210413030853-00422.warc.gz\"}"}