apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
9.84k stars 259 forks source link

Suggestion: Absent value for removing members #547

Open EugZol opened 1 week ago

EugZol commented 1 week ago

Currently in the language reference the following solution for removing fields is recommended:

// https://pkl-lang.org/main/current/language-reference/index.html#transforming-objects

dodo {
  name = "Dodo"
  extinct = true
}

dodo
  .toMap()
  .remove("name")
  .toDynamic()

Instead, create a built-in singleton value absent (similar to null), which would remove the corresponding member from the object:

dodo {
  name = "Dodo"
  extinct = true
}

dodoWithoutName  = (dodo) {
  name = absent
}
HT154 commented 1 day ago

Something similar has been discussed in the past using the delete keyword in the context of member predicates for amending Listings/Mappings. In terms of naming, I'm personally partial to omit, which is what Ansible uses for a similar action.