Skip to content
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

Merged
merged 8 commits into from
Oct 11, 2018

Conversation

jiegillet
Copy link
Collaborator

A couple of thoughts:

  • I'm not super happy about my modification of mkAnyValueBiMap, I couldn't use prism since the direction didn't work out, so I ended up using BiMap. It works, but it's a bit blunt.
  • This PR renders [Issue #70] Added function to create BiMap from concrete types #104 obsolete, probably
  • Maybe we need to add comments on _Show. Same as the others?
  • stack test runs fine

Happy to discuss more.

@jiegillet jiegillet mentioned this pull request Oct 7, 2018
6 tasks
@chshersh chshersh added codec Conversion between TOML and custom user data types refactoring Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Oct 7, 2018
@chshersh chshersh added this to In progress in #2: Hacktoberfest (October, 2018) via automation Oct 7, 2018
@chshersh
Copy link
Contributor

chshersh commented Oct 7, 2018

@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.

@jiegillet
Copy link
Collaborator Author

Please take your time.
The best motivation I could see for switching the arguments was to do this Toml._Left >>> Toml._Integer. Without using inverse it would not have been possible.

Copy link
Contributor

@chshersh chshersh left a 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?

@@ -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
Copy link
Contributor

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.

src/Toml/BiMap.hs Show resolved Hide resolved
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"
Copy link
Contributor

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 Show resolved Hide resolved
src/Toml/BiMap.hs Outdated Show resolved Hide resolved
_TextToString :: BiMap Text String
_TextToString = iso T.unpack T.pack
_StringToText :: BiMap String Text
_StringToText = iso T.pack T.unpack
Copy link
Contributor

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.

Copy link
Contributor

@chshersh chshersh left a 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)
Copy link
Contributor

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...

-- | 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
Copy link
Contributor

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

Copy link
Contributor

@chshersh chshersh left a 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
Copy link
Contributor

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 )

#2: Hacktoberfest (October, 2018) automation moved this from Reviewer approved to Done: PR's Oct 11, 2018
Copy link
Contributor

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 👏

#2: Hacktoberfest (October, 2018) automation moved this from In progress to Reviewer approved Oct 11, 2018
@chshersh chshersh merged commit a7b1f57 into kowainik:master Oct 11, 2018
@jiegillet jiegillet deleted the jie-bimap-swap branch November 7, 2018 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codec Conversion between TOML and custom user data types Hacktoberfest https://hacktoberfest.digitalocean.com/ refactoring
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants