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

support anchors and aliases in Data.Yaml.Builder #155

Merged
merged 6 commits into from
Sep 27, 2018

Conversation

dwightguth
Copy link
Contributor

No description provided.

mapping :: [(Text, YamlBuilder)] -> YamlBuilder
mapping pairs = YamlBuilder $ \rest ->
EventMappingStart NoTag AnyMapping Nothing : foldr addPair (EventMappingEnd : rest) pairs
namedMapping :: Maybe String -> [(Text, YamlBuilder)] -> YamlBuilder
Copy link
Owner

Choose a reason for hiding this comment

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

From an API design standpoint, I would have thought namedMapping would take a String, not a Maybe String, and you would use mapping when no name is available. Also, I would have thought we'd use Text instead of String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that, but then if you want to pass a Maybe to the function you'll have to do an if statement, which is cumbersome compared to the cost of wrapping the string in a Just. So maybe it's better to keep the signature and change the name of the function? Do you have a suggestion?

I will update to change the signature to a Text tomorrow.

@dwightguth
Copy link
Contributor Author

I've updated the Maybe to use Maybe Text instead of Maybe String, but I still prefer the signature of a Maybe to a plain Text, because it makes it easier to invoke the function if you have a Maybe as input, while still being pretty easy to construct a Maybe and call the function if you know that you definitely want an anchor. That said, I'm open to alternative naming suggestions for the functions if you have another idea.

@snoyberg
Copy link
Owner

I don't have another naming suggestion, though I still feel the same as before: the selected naming and type signature is confusing.

@dwightguth
Copy link
Contributor Author

I tried renaming the functions to maybeNamedMapping, maybeNamedString, etc. Is that more satisfactory to you?

@snoyberg
Copy link
Owner

I honestly think it's a bit weird to have the maybe version without the named version, but at this point I'll leave it as-is. Please adjust the PR to have the following:

  • Haddocks with @since comments on all newly exported identifiers
  • ChangeLog entry
  • Minor version bump

@dwightguth
Copy link
Contributor Author

dwightguth commented Sep 26, 2018

I went ahead and added the non-maybe version of the named functions based oh your suggestion, and also took into account your other suggested changes. Let me know if there's any other changes you want me to make.

@snoyberg snoyberg merged commit 0a56d96 into snoyberg:master Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants