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

Add convenient way to create YAML nodes in code #72

Merged
merged 2 commits into from
Oct 4, 2021

Conversation

kpodsiad
Copy link
Contributor

@kpodsiad kpodsiad commented Sep 19, 2021

Aims to close #68
Will be closed in a follow-up PR.

Current state: one can write sth like this

MappingNode(
      "hr"   -> ScalarNode("65"),
      "avg"  -> ScalarNode("0.278"),
      "blob" -> ScalarNode("nostradamus")
    )

I was thinking about implicit conversions that would allow more concise syntax:

MappingNode(
      "hr"   -> 65,
      "avg"  -> 0.278),
      "blob" -> "nostradamus",
      "bool_true" -> true,
      "bool_false" -> false,
    )

As we know, implicit conversions could be very tricky so I would prefer t place them at org.virtuslab.yaml.syntax to limit accidental import. In addition to import this package, user will have to import import scala.language.implicitConversions or set proper compiler option. Otherwise, he will get compiler warnings about usage of implicit conversion.
I find this proposal as a good balance between convenience and user awareness of what he is doing. What do you think?

@kpodsiad kpodsiad added the feature New feature or request label Sep 19, 2021
@kpodsiad kpodsiad added this to the M3 milestone Sep 19, 2021
@kpodsiad kpodsiad added this to In progress in scala-yaml via automation Sep 19, 2021
Copy link
Contributor

@lwronski lwronski left a comment

Choose a reason for hiding this comment

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

Good point, we should allow to use implicit conversions if the user imported special object from scala-yaml. We will add it in a separate PR.

Please, add at least one test for testing your implicit for nested yaml. For example

Sequence...
         Mapping...
         Mapping...

yaml/shared/src/main/scala/org/virtuslab/yaml/Node.scala Outdated Show resolved Hide resolved
Copy link
Contributor Author

@kpodsiad kpodsiad left a comment

Choose a reason for hiding this comment

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

LGTM, cannot approve because I'm author of the PR 😅

@kpodsiad kpodsiad merged commit 288be06 into main Oct 4, 2021
scala-yaml automation moved this from In progress to Done Oct 4, 2021
@kpodsiad kpodsiad deleted the dsl-for-creating-nodes branch October 4, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add API/dsl which will provide a convenient way to construct nodes
2 participants