-
-
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
[Issue #95 ]Reversed BiMap Anything a into BiMap a Anything #106
Conversation
@jiegillet Wow, you continue to bring very good improvements to the package! Let me take a look at the original issue and the original example one more time very carefully to make sure that we really need to swap order of arguments. |
Please take your time. |
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! I agree with the change after looking more closely at it.
Also, this is kinda serious breaking change, so, could you please update the changelog?
src/Toml/BiMap.hs
Outdated
@@ -67,10 +69,6 @@ instance Cat.Category BiMap where | |||
, backward = backward bc >=> backward ab | |||
} | |||
|
|||
-- | Inverts bidirectional mapping. | |||
invert :: BiMap a b -> BiMap b a | |||
invert (BiMap f g) = BiMap g f |
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.
It's still a good idea to have invert
function, it's somewhat idiomatic.
eitherT1 = Toml.match (Toml._Integer >>> Toml._Left) "either.Left" | ||
<|> Toml.match (Toml._String >>> Toml._Right) "either.Right" | ||
eitherT1 = Toml.match (Toml._Left >>> Toml._Integer) "either.Left" | ||
<|> Toml.match (Toml._Right >>> Toml._String) "either.Right" |
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.
Okay, looks like changing types of arguments pays off. I like this order of composition 👍 Lessons learned: Kmett always right.
src/Toml/BiMap.hs
Outdated
_TextToString :: BiMap Text String | ||
_TextToString = iso T.unpack T.pack | ||
_StringToText :: BiMap String Text | ||
_StringToText = iso T.pack T.unpack |
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.
I have better idea regarding naming convention: let's remove To
part from such prism. So it will be just: _StringText
. It doesn't make much sense to me now to have To
part because conversion is bidirectional.
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! Only couple minor comments left 👍
CHANGELOG.md
Outdated
@@ -6,6 +6,9 @@ The change log is available [on GitHub][2]. | |||
|
|||
0.5.0 | |||
===== | |||
|
|||
* [#106](https://github.com/kowainik/tomland/pull/106) |
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, please, change the link to the pull request here to the link for corresponding issue? The issue number is more important. I somehow missed it once, and now everyone specifies link to the PR...
src/Toml/BiMap.hs
Outdated
-- | Creates prism for 'Text' to 'AnyValue' bimap with custom functions | ||
_TextBy :: (Text -> Maybe a) -> (a -> Text) -> BiMap AnyValue a | ||
-- | Creates prism for 'Text' to 'AnyValue' with custom functions | ||
_TextBy :: (Text -> Maybe a) -> (a -> Text) -> BiMap a AnyValue |
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.
Let's also swap order of arguments for _TextBy
to be more consistent with the prism
combinator
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.
Only minor typo left. Otherwise it looks pretty nice!
CHANGELOG.md
Outdated
* [#106](https://github.com/kowainik/tomland/pull/106) | ||
Swap fields in BiMaps for consistency with `lens` package. | ||
* [#104](https://github.com/kowainik/tomland/pull/104) | ||
* [#95](https://github.com/kowainik/tomland/issues/95 |
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.
Probably a typo here: missing )
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! 👏
A couple of thoughts:
mkAnyValueBiMap
, I couldn't useprism
since the direction didn't work out, so I ended up usingBiMap
. It works, but it's a bit blunt._Show
. Same as the others?stack test
runs fineHappy to discuss more.