Skip to content

Conversation

@hg-pyun
Copy link
Collaborator

@hg-pyun hg-pyun commented Dec 26, 2025

Fixes #361

Summary

Add Map and Set support to the keys and values functions, following the established pattern in entries.ts.

Changes

  • keys: Now supports Map (yields keys) and Set (yields values, as Set keys equal values).
  • values: Now supports Map (yields values) and Set (yields values).
  • Runtime Tests: Added comprehensive tests for Map and Set support.
  • Type-check Tests: Added tests to ensure proper type inference is maintained.

Motivation

This change brings consistency across the entries, keys, and values functions. Previously, only entries supported Map and Set data structures (#362), while keys and values were limited to plain objects.

Usage

// keys - Map
[...keys(new Map([["a", 1], ["b", 2]]))] 
// ["a", "b"]

// keys - Set
[...keys(new Set([1, 2, 3]))] 
// [1, 2, 3]

// values - Map
[...values(new Map([["a", 1], ["b", 2]]))] 
// [1, 2]

// values - Set
[...values(new Set([1, 2, 3]))] 
// [1, 2, 3]

Type Safety

Full type inference is preserved:

keys(Map<K, V>) returns Generator<K, void>

keys(Set<V>) returns Generator<V, void>

values(Map<K, V>) returns Generator<V, void>

values(Set<V>) returns Generator<V, void>

⚠️ Breaking Changes

None. Existing code using keys and values with plain objects continues to work identically.

@hg-pyun hg-pyun self-assigned this Dec 26, 2025
@hg-pyun hg-pyun requested a review from ppeeou as a code owner December 26, 2025 02:36
Copy link
Member

@ppeeou ppeeou left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

@ppeeou ppeeou merged commit 600a8d7 into marpple:main Dec 29, 2025
1 check passed
@hg-pyun hg-pyun deleted the fix/issue-361-2 branch December 29, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object iteration functions do not work with Map and Set objects

2 participants