Member deletion #171

Open
opened 2025-12-30 01:21:43 +01:00 by adam · 1 comment
Owner

Originally created by @EugZol on GitHub (Jun 24, 2024).

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
}
Originally created by @EugZol on GitHub (Jun 24, 2024). Currently in the language reference the following solution for removing fields is recommended: ```pkl // 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 } ```
adam added the enhancement label 2025-12-30 01:21:43 +01:00
Author
Owner

@HT154 commented on GitHub (Jun 30, 2024):

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.

@HT154 commented on GitHub (Jun 30, 2024): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#171