Skip to content

feat: add entry-embeds matcher for predicate map keys (#132) - #244

Open
felipeofdev-ai wants to merge 1 commit into
nubank:masterfrom
felipeofdev-ai:feat/132-entry-embeds
Open

feat: add entry-embeds matcher for predicate map keys (#132)#244
felipeofdev-ai wants to merge 1 commit into
nubank:masterfrom
felipeofdev-ai:feat/132-entry-embeds

Conversation

@felipeofdev-ai

Copy link
Copy Markdown

Summary

Implements philomates' opt-in approach from #132: a new entry-embeds matcher for maps whose keys and/or values should be matched with predicates or submatchers.

Default map matching is unchanged — literal keys only. Predicate keys like {keyword? :b} still do not match {:a :b} unless wrapped in entry-embeds.

Fixes #132 (opt-in path; documents limitation for default maps)

Design

Following philomates' suggestion, map matching with predicate keys is recast as order-agnostic matching over [key-matcher value-matcher] entry pairs:

(is (match? (m/entry-embeds [[keyword? odd?] [:x pos?]])
            {:a 1 :x -1 :whatever "foo"}))

;; Duplicate key matchers (impossible in literal maps):
(is (match? (m/entry-embeds [[symbol? 2] [symbol? 1]])
            {'x 1 'y 2}))

Extra entries in the actual map are ignored (embeds semantics). Runtime is the same class as embeds / in-any-order — documented warning for large maps.

Changes

Test plan

  • New unit tests in core_test.clj and matchers_test.clj
  • Maintainer CI (Nu workflows)

— Felipe Fernandes · Systems & Agentic AI Engineer
https://github.com/felipeofdev-ai · https://felipeofdev-ai.github.io/

Opt-in matcher recasts map expectations as [key-matcher value-matcher] entry pairs, following philomates embeds-over-entries approach. Default map matching unchanged.

Signed-off-by: Felipe Fernandes <felipe.of.dev@gmail.com>
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.

match? mismatches predicates when applied to keys in maps

1 participant