-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
[#82] Remove maybeT, add diOptional #101
Conversation
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.
Great implementation!
@@ -25,6 +25,8 @@ The change log is available [on GitHub][2]. | |||
Improve `Double` generator for property-based tests. | |||
* Add support for GHC 8.6.1. | |||
Drop support for GHC 8.0.2. | |||
* [#82](https://github.com/kowainik/tomland/issues/82): | |||
Remove `maybeT`. Add `diOptional`. |
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.
Could you also bump up cabal-version
in .cabal
file as well? I see that it's still 0.4.1
for a very long time...
src/Toml/Bi/Combinators.hs
Outdated
@@ -16,8 +16,8 @@ module Toml.Bi.Combinators | |||
, arrayOf | |||
|
|||
-- * Combinators | |||
, diOptional |
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.
The O
letter should be small, so it's just dioptional
. Standard naming convention for profunctor functions
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.
Also, since function works with general Codec
, it should go to the Toml.Bi.Monad
module
src/Toml/Bi/Combinators.hs
Outdated
maybeT :: forall a . (Key -> TomlCodec a) -> Key -> TomlCodec (Maybe a) | ||
maybeT converter key = let codec = converter key in Codec | ||
{ codecRead = (Just <$> codecRead codec) `catchError` handleNotFound | ||
diOptional :: (Functor r, Functor w, Applicative w) => Codec r w c a -> Codec r w (Maybe c) (Maybe a) |
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.
Functor
is a superclass of Applicative
, so it's enough to have only Applicative w
in the constraints.
src/Toml/Bi/Combinators.hs
Outdated
, codecWrite = \case | ||
Nothing -> pure Nothing | ||
Just v -> codecWrite codec v >> pure (Just v) | ||
Just c -> Just <$> codecWrite c |
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.
Nice! You've just implemented Traversable
instance for Maybe
. If you look at this instance, you probably might notice how to implement codecWrite
in more concise way:
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.
If so, maybe someday I will implement somewhat function for relude
:)
src/Toml/Bi/Combinators.hs
Outdated
maybeT converter key = let codec = converter key in Codec | ||
{ codecRead = (Just <$> codecRead codec) `catchError` handleNotFound | ||
diOptional :: (Functor r, Functor w, Applicative w) => Codec r w c a -> Codec r w (Maybe c) (Maybe a) | ||
diOptional Codec {..} = Codec |
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.
There should be no space between Codec
and {..}
Travis fails with an error for |
@vrom911 Thank you very much for working on this! 💖 |
It seems it fixed itself. Version |
While I slept the problem with |
76d406a
to
9f3ca9e
Compare
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.
Great!
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.
Looks great!
Resolves: #82