-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
src/Data/Yaml/Builder.hs
Outdated
mapping :: [(Text, YamlBuilder)] -> YamlBuilder | ||
mapping pairs = YamlBuilder $ \rest -> | ||
EventMappingStart NoTag AnyMapping Nothing : foldr addPair (EventMappingEnd : rest) pairs | ||
namedMapping :: Maybe String -> [(Text, YamlBuilder)] -> YamlBuilder |
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.
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
.
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.
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.
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. |
I don't have another naming suggestion, though I still feel the same as before: the selected naming and type signature is confusing. |
I tried renaming the functions to maybeNamedMapping, maybeNamedString, etc. Is that more satisfactory to you? |
I honestly think it's a bit weird to have the
|
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. |
No description provided.