| Copyright | (c) 2013-2023 Brendan Hay |
|---|---|
| License | Mozilla Public License, v. 2.0. |
| Maintainer | Brendan Hay <brendan.g.hay+amazonka@gmail.com> |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Test.Amazonka.Prelude
Description
Synopsis
- traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
- class Profunctor p => Choice (p :: Type -> Type -> Type)
- type Optic' (p :: k -> k1 -> Type) (f :: k -> k1) (s :: k) (a :: k) = Optic p f s s a a
- type Fold s a = forall (f :: Type -> Type). (Contravariant f, Applicative f) => (a -> f a) -> s -> f s
- type Getter s a = forall (f :: Type -> Type). (Contravariant f, Functor f) => (a -> f a) -> s -> f s
- type Prism' s a = Prism s s a a
- type AReview t b = Optic' (Tagged :: Type -> Type -> Type) Identity t b
- type Iso' s a = Iso s s a a
- type Setter' s a = Setter s s a a
- type IndexedTraversal' i s a = IndexedTraversal i s s a a
- type Traversal' s a = Traversal s s a a
- type Lens' s a = Lens s s a a
- type Lens s t a b = forall (f :: Type -> Type). Functor f => (a -> f b) -> s -> f t
- sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Optical p q f s t a b
- (%~) :: ASetter s t a b -> (a -> b) -> s -> t
- (.~) :: ASetter s t a b -> b -> s -> t
- (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
- (<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- type Getting r s a = (a -> Const r a) -> s -> Const r s
- to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a
- view :: MonadReader s m => Getting a s a -> m a
- (^.) :: s -> Getting a s a -> a
- un :: (Profunctor p, Bifunctor p, Functor f) => Getting a s a -> Optic' p f a s
- (#) :: AReview t b -> b -> t
- prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
- _Just :: Prism (Maybe a) (Maybe b) a b
- folding :: Foldable f => (s -> f a) -> Fold s a
- filtered :: (Choice p, Applicative f) => (a -> Bool) -> Optic' p f a a
- (^..) :: s -> Getting (Endo [a]) s a -> [a]
- anyOf :: Getting Any s a -> (a -> Bool) -> s -> Bool
- allOf :: Getting All s a -> (a -> Bool) -> s -> Bool
- concatOf :: Getting [r] s [r] -> s -> [r]
- (^?) :: s -> Getting (First a) s a -> Maybe a
- has :: Getting Any s a -> s -> Bool
- traversed :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int (f a) (f b) a b
- iso :: (s -> a) -> (b -> t) -> Iso s t a b
- mapping :: forall (f :: Type -> Type) (g :: Type -> Type) s t a b. (Functor f, Functor g) => AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
- non :: Eq a => a -> Iso' (Maybe a) a
- coerced :: forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
- _last :: Snoc s s a a => Traversal' s a
- exception :: Exception a => Prism' SomeException a
- catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r
- catching_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m r -> m r
- trying :: MonadCatch m => Getting (First a) SomeException a -> m r -> m (Either a r)
- throwingM :: MonadThrow m => AReview SomeException b -> b -> m r
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- _IOException :: AsIOException t => Prism' t IOException
- _1 :: Field1 s t a b => Lens s t a b
- _2 :: Field2 s t a b => Lens s t a b
- testGroup :: TestName -> [TestTree] -> TestTree
- data TestTree
- testCase :: TestName -> Assertion -> TestTree
- assertDiff :: (Eq a, Show a) => String -> a -> Either String a -> Assertion
- mkTime :: Text -> Q Exp
Documentation
traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) #
Map each element of a structure to an action, evaluate these actions
from left to right, and collect the results. For a version that ignores
the results see traverse_.
Examples
Basic usage:
In the first two examples we show each evaluated action mapping to the output structure.
>>>traverse Just [1,2,3,4]Just [1,2,3,4]
>>>traverse id [Right 1, Right 2, Right 3, Right 4]Right [1,2,3,4]
In the next examples, we show that Nothing and Left values short
circuit the created structure.
>>>traverse (const Nothing) [1,2,3,4]Nothing
>>>traverse (\x -> if odd x then Just x else Nothing) [1,2,3,4]Nothing
>>>traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]Left 0
class Profunctor p => Choice (p :: Type -> Type -> Type) #
The generalization of Costar of Functor that is strong with respect
to Either.
Note: This is also a notion of strength, except with regards to another monoidal structure that we can choose to equip Hask with: the cocartesian coproduct.
Instances
type Fold s a = forall (f :: Type -> Type). (Contravariant f, Applicative f) => (a -> f a) -> s -> f s #
A Fold describes how to retrieve multiple values in a way that can be composed
with other LensLike constructions.
A provides a structure with operations very similar to those of the Fold s aFoldable
typeclass, see foldMapOf and the other Fold combinators.
By convention, if there exists a foo method that expects a , then there should be a
Foldable (f a)fooOf method that takes a and a value of type Fold s as.
A Getter is a legal Fold that just ignores the supplied Monoid.
Unlike a Traversal a Fold is read-only. Since a Fold cannot be used to write back
there are no Lens laws that apply.
type Getter s a = forall (f :: Type -> Type). (Contravariant f, Functor f) => (a -> f a) -> s -> f s #
A Getter describes how to retrieve a single value in a way that can be
composed with other LensLike constructions.
Unlike a Lens a Getter is read-only. Since a Getter
cannot be used to write back there are no Lens laws that can be applied to
it. In fact, it is isomorphic to an arbitrary function from (s -> a).
Moreover, a Getter can be used directly as a Fold,
since it just ignores the Applicative.
type IndexedTraversal' i s a = IndexedTraversal i s s a a #
typeIndexedTraversal'i =Simple(IndexedTraversali)
type Traversal' s a = Traversal s s a a #
typeTraversal'=SimpleTraversal
type Lens s t a b = forall (f :: Type -> Type). Functor f => (a -> f b) -> s -> f t #
A Lens is actually a lens family as described in
http://comonad.com/reader/2012/mirrored-lenses/.
With great power comes great responsibility and a Lens is subject to the
three common sense Lens laws:
1) You get back what you put in:
viewl (setl v s) ≡ v
2) Putting back what you got doesn't change anything:
setl (viewl s) s ≡ s
3) Setting twice is the same as setting once:
setl v' (setl v s) ≡setl v' s
These laws are strong enough that the 4 type parameters of a Lens cannot
vary fully independently. For more on how they interact, read the "Why is
it a Lens Family?" section of
http://comonad.com/reader/2012/mirrored-lenses/.
There are some emergent properties of these laws:
1) must be injective for every set l ss This is a consequence of law #1
2) must be surjective, because of law #2, which indicates that it is possible to obtain any set lv from some s such that set s v = s
3) Given just the first two laws you can prove a weaker form of law #3 where the values v that you are setting match:
setl v (setl v s) ≡setl v s
Every Lens can be used directly as a Setter or Traversal.
You can also use a Lens for Getting as if it were a
Fold or Getter.
Since every Lens is a valid Traversal, the
Traversal laws are required of any Lens you create:
lpure≡purefmap(l f).l g ≡getCompose.l (Compose.fmapf.g)
typeLenss t a b = forall f.Functorf =>LensLikef s t a b
sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Optical p q f s t a b #
Build a Setter, IndexedSetter or IndexPreservingSetter depending on your choice of Profunctor.
sets:: ((a -> b) -> s -> t) ->Setters t a b
(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #
Modifies the target of a Lens or all of the targets of a Setter or
Traversal with a user supplied function.
This is an infix version of over.
fmapf ≡mapped%~ffmapDefaultf ≡traverse%~f
>>>(a,b,c) & _3 %~ f(a,b,f c)
>>>(a,b) & both %~ f(f a,f b)
>>>_2 %~ length $ (1,"hello")(1,5)
>>>traverse %~ f $ [a,b,c][f a,f b,f c]
>>>traverse %~ even $ [1,2,3][False,True,False]
>>>traverse.traverse %~ length $ [["hello","world"],["!!!"]][[5,5],[3]]
(%~) ::Setters t a b -> (a -> b) -> s -> t (%~) ::Isos t a b -> (a -> b) -> s -> t (%~) ::Lenss t a b -> (a -> b) -> s -> t (%~) ::Traversals t a b -> (a -> b) -> s -> t
(.~) :: ASetter s t a b -> b -> s -> t infixr 4 #
Replace the target of a Lens or all of the targets of a Setter
or Traversal with a constant value.
This is an infix version of set, provided for consistency with (.=).
f<$a ≡mapped.~f$a
>>>(a,b,c,d) & _4 .~ e(a,b,c,e)
>>>(42,"world") & _1 .~ "hello"("hello","world")
>>>(a,b) & both .~ c(c,c)
(.~) ::Setters t a b -> b -> s -> t (.~) ::Isos t a b -> b -> s -> t (.~) ::Lenss t a b -> b -> s -> t (.~) ::Traversals t a b -> b -> s -> t
(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 #
Set the target of a Lens, Traversal or Setter to Just a value.
l?~t ≡setl (Justt)
>>>Nothing & id ?~ aJust a
>>>Map.empty & at 3 ?~ xfromList [(3,x)]
?~ can be used type-changily:
>>>('a', ('b', 'c')) & _2.both ?~ 'x'('a',(Just 'x',Just 'x'))
(?~) ::Setters t a (Maybeb) -> b -> s -> t (?~) ::Isos t a (Maybeb) -> b -> s -> t (?~) ::Lenss t a (Maybeb) -> b -> s -> t (?~) ::Traversals t a (Maybeb) -> b -> s -> t
(<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t infixr 4 #
Modify the target of a Semigroup value by using (.<>)
>>>(Sum a,b) & _1 <>~ Sum c(Sum {getSum = a + c},b)
>>>(Sum a,Sum b) & both <>~ Sum c(Sum {getSum = a + c},Sum {getSum = b + c})
>>>both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")
(<>~) ::Semigroupa =>Setters t a a -> a -> s -> t (<>~) ::Semigroupa =>Isos t a a -> a -> s -> t (<>~) ::Semigroupa =>Lenss t a a -> a -> s -> t (<>~) ::Semigroupa =>Traversals t a a -> a -> s -> t
type Getting r s a = (a -> Const r a) -> s -> Const r s #
When you see this in a type signature it indicates that you can
pass the function a Lens, Getter,
Traversal, Fold,
Prism, Iso, or one of
the indexed variants, and it will just "do the right thing".
Most Getter combinators are able to be used with both a Getter or a
Fold in limited situations, to do so, they need to be
monomorphic in what we are going to extract with Const. To be compatible
with Lens, Traversal and
Iso we also restricted choices of the irrelevant t and
b parameters.
If a function accepts a , then when Getting r s ar is a Monoid, then
you can pass a Fold (or
Traversal), otherwise you can only pass this a
Getter or Lens.
to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a #
view :: MonadReader s m => Getting a s a -> m a #
View the value pointed to by a Getter, Iso or
Lens or the result of folding over all the results of a
Fold or Traversal that points
at a monoidal value.
view.to≡id
>>>view (to f) af a
>>>view _2 (1,"hello")"hello"
>>>view (to succ) 56
>>>view (_2._1) ("hello",("world","!!!"))"world"
As view is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold,
It may be useful to think of it as having one of these more restricted signatures:
view::Getters a -> s -> aview::Monoidm =>Folds m -> s -> mview::Iso's a -> s -> aview::Lens's a -> s -> aview::Monoidm =>Traversal's m -> s -> m
In a more general setting, such as when working with a Monad transformer stack you can use:
view::MonadReaders m =>Getters a -> m aview:: (MonadReaders m,Monoida) =>Folds a -> m aview::MonadReaders m =>Iso's a -> m aview::MonadReaders m =>Lens's a -> m aview:: (MonadReaders m,Monoida) =>Traversal's a -> m a
(^.) :: s -> Getting a s a -> a infixl 8 #
View the value pointed to by a Getter or Lens or the
result of folding over all the results of a Fold or
Traversal that points at a monoidal values.
This is the same operation as view with the arguments flipped.
The fixity and semantics are such that subsequent field accesses can be
performed with (.).
>>>(a,b)^._2b
>>>("hello","world")^._2"world"
>>>import Data.Complex>>>((0, 1 :+ 2), 3)^._1._2.to magnitude2.23606797749979
(^.) :: s ->Getters a -> a (^.) ::Monoidm => s ->Folds m -> m (^.) :: s ->Iso's a -> a (^.) :: s ->Lens's a -> a (^.) ::Monoidm => s ->Traversal's m -> m
(#) :: AReview t b -> b -> t infixr 8 #
An infix alias for review.
untof # x ≡ f x l # x ≡ x^.rel
This is commonly used when using a Prism as a smart constructor.
>>>_Left # 4Left 4
But it can be used for any Prism
>>>base 16 # 123"7b"
(#) ::Iso's a -> a -> s (#) ::Prism's a -> a -> s (#) ::Reviews a -> a -> s (#) ::Equality's a -> a -> s
_Just :: Prism (Maybe a) (Maybe b) a b #
This Prism provides a Traversal for tweaking the target of the value of Just in a Maybe.
>>>over _Just (+1) (Just 2)Just 3
Unlike traverse this is a Prism, and so you can use it to inject as well:
>>>_Just # 5Just 5
>>>5^.re _JustJust 5
Interestingly,
m^?_Just≡ m
>>>Just x ^? _JustJust x
>>>Nothing ^? _JustNothing
filtered :: (Choice p, Applicative f) => (a -> Bool) -> Optic' p f a a #
Obtain a Fold that can be composed with to filter another Lens, Iso, Getter, Fold (or Traversal).
Note: This is not a legal Traversal, unless you are very careful not to invalidate the predicate on the target.
Note: This is also not a legal Prism, unless you are very careful not to inject a value that fails the predicate.
As a counter example, consider that given evens = the second filtered evenTraversal law is violated:
overevenssucc.overevenssucc/=overevens (succ.succ)
So, in order for this to qualify as a legal Traversal you can only use it for actions that preserve the result of the predicate!
>>>[1..10]^..folded.filtered even[2,4,6,8,10]
This will preserve an index if it is present.
(^..) :: s -> Getting (Endo [a]) s a -> [a] infixl 8 #
A convenient infix (flipped) version of toListOf.
>>>[[1,2],[3]]^..id[[[1,2],[3]]]>>>[[1,2],[3]]^..traverse[[1,2],[3]]>>>[[1,2],[3]]^..traverse.traverse[1,2,3]
>>>(1,2)^..both[1,2]
toListxs ≡ xs^..folded(^..) ≡fliptoListOf
(^..) :: s ->Getters a -> a :: s ->Folds a -> a :: s ->Lens's a -> a :: s ->Iso's a -> a :: s ->Traversal's a -> a :: s ->Prism's a -> [a]
anyOf :: Getting Any s a -> (a -> Bool) -> s -> Bool #
Returns True if any target of a Fold satisfies a predicate.
>>>anyOf both (=='x') ('x','y')True>>>import Data.Data.Lens>>>anyOf biplate (== "world") (((),2::Int),"hello",("world",11::Int))True
any≡anyOffolded
ianyOfl ≡anyOfl.Indexed
anyOf::Getters a -> (a ->Bool) -> s ->BoolanyOf::Folds a -> (a ->Bool) -> s ->BoolanyOf::Lens's a -> (a ->Bool) -> s ->BoolanyOf::Iso's a -> (a ->Bool) -> s ->BoolanyOf::Traversal's a -> (a ->Bool) -> s ->BoolanyOf::Prism's a -> (a ->Bool) -> s ->Bool
allOf :: Getting All s a -> (a -> Bool) -> s -> Bool #
Returns True if every target of a Fold satisfies a predicate.
>>>allOf both (>=3) (4,5)True>>>allOf folded (>=2) [1..10]False
all≡allOffolded
iallOfl =allOfl.Indexed
allOf::Getters a -> (a ->Bool) -> s ->BoolallOf::Folds a -> (a ->Bool) -> s ->BoolallOf::Lens's a -> (a ->Bool) -> s ->BoolallOf::Iso's a -> (a ->Bool) -> s ->BoolallOf::Traversal's a -> (a ->Bool) -> s ->BoolallOf::Prism's a -> (a ->Bool) -> s ->Bool
concatOf :: Getting [r] s [r] -> s -> [r] #
Concatenate all of the lists targeted by a Fold into a longer list.
>>>concatOf both ("pan","ama")"panama"
concat≡concatOffoldedconcatOf≡view
concatOf::Getters [r] -> s -> [r]concatOf::Folds [r] -> s -> [r]concatOf::Iso's [r] -> s -> [r]concatOf::Lens's [r] -> s -> [r]concatOf::Traversal's [r] -> s -> [r]
(^?) :: s -> Getting (First a) s a -> Maybe a infixl 8 #
Perform a safe head of a Fold or Traversal or retrieve Just the result
from a Getter or Lens.
When using a Traversal as a partial Lens, or a Fold as a partial Getter this can be a convenient
way to extract the optional value.
Note: if you get stack overflows due to this, you may want to use firstOf instead, which can deal
more gracefully with heavily left-biased trees. This is because ^? works by using the
First monoid, which can occasionally cause space leaks.
>>>Left 4 ^?_LeftJust 4
>>>Right 4 ^?_LeftNothing
>>>"world" ^? ix 3Just 'l'
>>>"world" ^? ix 20Nothing
This operator works as an infix version of preview.
(^?) ≡flippreview
It may be helpful to think of ^? as having one of the following
more specialized types:
(^?) :: s ->Getters a ->Maybea (^?) :: s ->Folds a ->Maybea (^?) :: s ->Lens's a ->Maybea (^?) :: s ->Iso's a ->Maybea (^?) :: s ->Traversal's a ->Maybea
has :: Getting Any s a -> s -> Bool #
Check to see if this Fold or Traversal matches 1 or more entries.
>>>has (element 0) []False
>>>has _Left (Left 12)True
>>>has _Right (Left 12)False
This will always return True for a Lens or Getter.
>>>has _1 ("hello","world")True
has::Getters a -> s ->Boolhas::Folds a -> s ->Boolhas::Iso's a -> s ->Boolhas::Lens's a -> s ->Boolhas::Traversal's a -> s ->Bool
traversed :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int (f a) (f b) a b #
Traverse any Traversable container. This is an IndexedTraversal that is indexed by ordinal position.
mapping :: forall (f :: Type -> Type) (g :: Type -> Type) s t a b. (Functor f, Functor g) => AnIso s t a b -> Iso (f s) (g t) (f a) (g b) #
non :: Eq a => a -> Iso' (Maybe a) a #
If v is an element of a type a, and a' is a sans the element v, then is an isomorphism from
non v to Maybe a'a.
non≡non'.only
Keep in mind this is only a real isomorphism if you treat the domain as being .Maybe (a sans v)
This is practically quite useful when you want to have a Map where all the entries should have non-zero values.
>>>Map.fromList [("hello",1)] & at "hello" . non 0 +~ 2fromList [("hello",3)]
>>>Map.fromList [("hello",1)] & at "hello" . non 0 -~ 1fromList []
>>>Map.fromList [("hello",1)] ^. at "hello" . non 01
>>>Map.fromList [] ^. at "hello" . non 00
This combinator is also particularly useful when working with nested maps.
e.g. When you want to create the nested Map when it is missing:
>>>Map.empty & at "hello" . non Map.empty . at "world" ?~ "!!!"fromList [("hello",fromList [("world","!!!")])]
and when have deleting the last entry from the nested Map mean that we
should delete its entry from the surrounding one:
>>>Map.fromList [("hello",Map.fromList [("world","!!!")])] & at "hello" . non Map.empty . at "world" .~ NothingfromList []
It can also be used in reverse to exclude a given value:
>>>non 0 # rem 10 4Just 2
>>>non 0 # rem 10 5Nothing
coerced :: forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b #
Data types that are representationally equal are isomorphic.
This is only available on GHC 7.8+
Since: lens-4.13
_last :: Snoc s s a a => Traversal' s a #
A Traversal reading and writing to the last element of a non-empty container.
>>>[a,b,c]^?!_lastc
>>>[]^?_lastNothing
>>>[a,b,c] & _last %~ f[a,b,f c]
>>>[1,2]^?_lastJust 2
>>>[] & _last .~ 1[]
>>>[0] & _last .~ 2[2]
>>>[0,1] & _last .~ 2[0,2]
This Traversal is not limited to lists, however. We can also work with other containers, such as a Vector.
>>>Vector.fromList "abcde" ^? _lastJust 'e'
>>>Vector.empty ^? _lastNothing
>>>(Vector.fromList "abcde" & _last .~ 'Q') == Vector.fromList "abcdQ"True
_last::Traversal'[a] a_last::Traversal'(Seqa) a_last::Traversal'(Vectora) a
exception :: Exception a => Prism' SomeException a #
Traverse the strongly typed Exception contained in SomeException where the type of your function matches
the desired Exception.
exception:: (Applicativef,Exceptiona) => (a -> f a) ->SomeException-> fSomeException
catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r #
Catch exceptions that match a given ReifiedPrism (or any ReifiedFold, really).
>>>catching _AssertionFailed (assert False (return "uncaught")) $ \ _ -> return "caught""caught"
catching::MonadCatchm =>Prism'SomeExceptiona -> m r -> (a -> m r) -> m rcatching::MonadCatchm =>Lens'SomeExceptiona -> m r -> (a -> m r) -> m rcatching::MonadCatchm =>Traversal'SomeExceptiona -> m r -> (a -> m r) -> m rcatching::MonadCatchm =>Iso'SomeExceptiona -> m r -> (a -> m r) -> m rcatching::MonadCatchm =>ReifiedGetterSomeExceptiona -> m r -> (a -> m r) -> m rcatching::MonadCatchm =>ReifiedFoldSomeExceptiona -> m r -> (a -> m r) -> m r
catching_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m r -> m r #
Catch exceptions that match a given ReifiedPrism (or any ReifiedGetter), discarding
the information about the match. This is particularly useful when you have
a where the result of the Prism' e ()ReifiedPrism or ReifiedFold isn't
particularly valuable, just the fact that it matches.
>>>catching_ _AssertionFailed (assert False (return "uncaught")) $ return "caught""caught"
catching_::MonadCatchm =>Prism'SomeExceptiona -> m r -> m r -> m rcatching_::MonadCatchm =>Lens'SomeExceptiona -> m r -> m r -> m rcatching_::MonadCatchm =>Traversal'SomeExceptiona -> m r -> m r -> m rcatching_::MonadCatchm =>Iso'SomeExceptiona -> m r -> m r -> m rcatching_::MonadCatchm =>ReifiedGetterSomeExceptiona -> m r -> m r -> m rcatching_::MonadCatchm =>ReifiedFoldSomeExceptiona -> m r -> m r -> m r
trying :: MonadCatch m => Getting (First a) SomeException a -> m r -> m (Either a r) #
A variant of try that takes a ReifiedPrism (or any ReifiedFold) to select which
exceptions are caught (c.f. tryJust, catchJust). If the
Exception does not match the predicate, it is re-thrown.
trying::MonadCatchm =>Prism'SomeExceptiona -> m r -> m (Eithera r)trying::MonadCatchm =>Lens'SomeExceptiona -> m r -> m (Eithera r)trying::MonadCatchm =>Traversal'SomeExceptiona -> m r -> m (Eithera r)trying::MonadCatchm =>Iso'SomeExceptiona -> m r -> m (Eithera r)trying::MonadCatchm =>ReifiedGetterSomeExceptiona -> m r -> m (Eithera r)trying::MonadCatchm =>ReifiedFoldSomeExceptiona -> m r -> m (Eithera r)
throwingM :: MonadThrow m => AReview SomeException b -> b -> m r #
A variant of throwing that can only be used within the IO Monad
(or any other MonadCatch instance) to throw an Exception described
by a ReifiedPrism.
Although throwingM has a type that is a specialization of the type of
throwing, the two functions are subtly different:
throwingl e `seq` x ≡throwingethrowingMl e `seq` x ≡ x
The first example will cause the Exception e to be raised, whereas the
second one won't. In fact, throwingM will only cause an Exception to
be raised when it is used within the MonadCatch instance. The throwingM
variant should be used in preference to throwing to raise an Exception
within the Monad because it guarantees ordering with respect to other
monadic operations, whereas throwing does not.
throwingMl ≡reviewslthrow
throwingM::MonadThrowm =>Prism'SomeExceptiont -> t -> m rthrowingM::MonadThrowm =>Iso'SomeExceptiont -> t -> m r
_IOException :: AsIOException t => Prism' t IOException #
Unfortunately the name ioException is taken by base for
throwing IOExceptions.
_IOException::Prism'IOExceptionIOException_IOException::Prism'SomeExceptionIOException
Many combinators for working with an IOException are available
in System.IO.Error.Lens.
_1 :: Field1 s t a b => Lens s t a b #
Access the 1st field of a tuple (and possibly change its type).
>>>(1,2)^._11
>>>_1 .~ "hello" $ (1,2)("hello",2)
>>>(1,2) & _1 .~ "hello"("hello",2)
>>>_1 putStrLn ("hello","world")hello ((),"world")
This can also be used on larger tuples as well:
>>>(1,2,3,4,5) & _1 +~ 41(42,2,3,4,5)
_1::Lens(a,b) (a',b) a a'_1::Lens(a,b,c) (a',b,c) a a'_1::Lens(a,b,c,d) (a',b,c,d) a a' ..._1::Lens(a,b,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'
_2 :: Field2 s t a b => Lens s t a b #
Access the 2nd field of a tuple.
>>>_2 .~ "hello" $ (1,(),3,4)(1,"hello",3,4)
>>>(1,2,3,4) & _2 *~ 3(1,6,3,4)
>>>_2 print (1,2)2 (1,())
anyOf_2:: (s ->Bool) -> (a, s) ->Booltraverse._2:: (Applicativef,Traversablet) => (a -> f b) -> t (s, a) -> f (t (s, b))foldMapOf(traverse._2) :: (Traversablet,Monoidm) => (s -> m) -> t (b, s) -> m
The main data structure defining a test suite.
It consists of individual test cases and properties, organized in named groups which form a tree-like hierarchy.
There is no generic way to create a test case. Instead, every test
provider (tasty-hunit, tasty-smallcheck etc.) provides a function to
turn a test case into a TestTree.
Groups can be created using testGroup.