practicalli / practicalli/clojure

Aliases in clojure.spec

Open
#28 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

spec
Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

Is there a way to use spec on a map without mandating that the kw and spec have the same name? Like
{:sponsor value-conforming-to-:person-spec}

If you're working with unqualified keys, probably the simplest workaround would be an alias spec:

(s/def ::person-spec ,,, whatever ,,,)
(s/def :person/sponsor ::person-spec)
(s/def ::sponsor-map (s/keys :req-un [:person/sponsor ,,,]))

That key will be :sponsor but the spec will be :person/sponsor which is aliased to ::person-spec.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's Clojure spec examples, especially s/def, s/keys, and the proposed alias between ::person-spec and :person/sponsor. Clarify whether this pattern is supported and document the recommended way to use a differently named spec with a map key.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.