-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add traceAll #3
add traceAll #3
Conversation
Looks good to me, but I would suggest factoring it like this: traceTraversable :: (Applicative m, Traversable t) => Tracer m a -> Tracer m (t a)
traceTraversable tr = Tracer (void . traverse (runTracer tr))
traceAll :: (Applicative m, Traversable t) => (b -> t a) -> Tracer m a -> Tracer m b
traceAll f = contramap f . traceTraversable |
or maybe we should go one step further: mapTracer :: ((a -> m ()) -> b -> n ())
-> Tracer m a -> Tracer n b
mapTracer f (Tracer tr) = Tracer (f tr)
natTracer :: (forall x. m x -> n x)
-> Tracer m a
-> Tracer n a
natTracer f = mapTracer (f .)
instance Contravariant (Tracer m) where
contramap f = mapTracer (. f)
contramapM :: Monad m
=> (a -> m b)
-> Tracer m b
-> Tracer m a
contramapM f = mapTracer (f >=>)
-- by using `traverse_` we can reduce the constraint of `t` to `Foldable t`.
traceTraversable :: (Applicative m, Foldable t) => Tracer m a -> Tracer m (t a)
traceTraversable = mapTracer traverse_ |
Thank you 🙇 for the review. Applied suggestion with traceTraversable and mapTracer. New functions are exposed.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small formatting suggestions.
Could you just squash the review commits onto the other ones? Then it's ready to be merged. |
@coot Commits from PR were squashed. Thank you for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your contribution.
Hello,
Thank you for lovely ❤️ library. Often I am in a situation where I have tracer for e.g. Transaction
and I have Block full of transactions:
I know how to get Transactions from Block.
I would like to trace all transactions from Block. Result from Tracer is IO () so If I can smash together results. PR contains (generalised) combinator for this:
You can use it like so:
You could play this game with Maybe or any other Traversable.