Skip to content

polyglot-scala: Proposal for better Config #146

Closed
@lefou

Description

@lefou

TL;DR

Allow empty Config() instances to model empty XML leaf nodes.
Before I prepare a PR, I'd like to have your support.


Long Version

The dynamic apply of Configs companion object is very convenient.

Unfortunatelly, creating empty elements (no context and/or no attribute) is currently not supported.
But if you need that, e.g. when using the maven-antrun-plugin, you have to fall back to the class constructor of Config, which is a lot less convenient, harder to read and feels inconsistent compared to the rest of the pom.scala.

Examle:

configuration = Config(
  key1 = "value1"
)

produces:

<configuration>
  <key1>value1</key>
</configuration>

but to add a

<key2/>

I need to convert the complete block to use the constructor of Config which is a cumbersome process and harder to read.

configuration = new Config(Seq(
  "key1" -> Some( "value1"),
  "key2" -> None
))

What if we would allow and support the empty Config() or Config.Empty for this? With this, it would be much more convenient:

configuration = Config(
  key1 = "value1",
  key2 = Config.Empty
)

This was the first part of this proposal.

The second part is about making the Config constructor simpler. The current constructor looks like this:

class Config(val elements: immutable.Seq[(String, Option[Any])])

Now that we have elaborated a way to produce empty elements, there is no longer a need to have that Option. An empty element is one that holds a Config.Empty, all others are non-empty.

So the simplified constructor would look like:

class Config(val elements: immutable.Seq[(String, Any)])

What do you think?

After a discussion and your "go", I'm glad to provide a pull request.

@huntc Could you comment, please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions