Skip to content

feat(common): support collection-style access to YamlList and YamlMap - #30

Open
WhiredPlanck wants to merge 1 commit into
Heapy:mainfrom
WhiredPlanck:iterable-interface
Open

feat(common): support collection-style access to YamlList and YamlMap #30
WhiredPlanck wants to merge 1 commit into
Heapy:mainfrom
WhiredPlanck:iterable-interface

Conversation

@WhiredPlanck

@WhiredPlanck WhiredPlanck commented Aug 31, 2026

Copy link
Copy Markdown

Makes YamlList and YamlMap iterable, so collection functions like map() and associate() work on them directly instead of on .items / .entries. YamlMap additionally gets mapKeys, mapValues, filterKeys, filterValues and getValue(key) extensions for the key-based operations that iteration can't express.

The concrete code this enables:

// before
node.yamlMap.entries.associate { (key, value) -> key.content to value.yamlScalar.content }
// after
node.yamlMap.associate { (key, value) -> key.content to value.yamlScalar.content }

This is a polishment of #24, I still implement Iterable for YamlMap because .associate is only available on Iterable, and can reduce a lot of custom extension functions for YamlMap.

Make YamlList and YamlMap iterable, so collection functions like
map() and associate() can be used directly on them instead of on
their items or entries.

YamlMap also gains mapKeys, mapValues, filterKeys, filterValues and
getValue(key) extensions for the key-based operations that iteration
cannot provide; filterKeys/filterValues return a YamlMap, the others
return plain maps.

All changes are additive — equality semantics and the existing public
API are untouched.
@WhiredPlanck WhiredPlanck changed the title feat(common): make YamlList and YamlMap iterable @WhiredPlanck feat(common): support collection-style access to YamlList and YamlMap Aug 31, 2026
@WhiredPlanck WhiredPlanck changed the title @WhiredPlanck feat(common): support collection-style access to YamlList and YamlMap feat(common): support collection-style access to YamlList and YamlMap Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant