Skip to content

Instantly share code, notes, and snippets.

@aamedina
Last active May 12, 2019 19:52
Show Gist options
  • Select an option

  • Save aamedina/0ac69540b092c06d96cfe42d76591295 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/0ac69540b092c06d96cfe42d76591295 to your computer and use it in GitHub Desktop.
This describes an enumerated set of valid months in the calendar. I love how easy in Clojure it is to read, write, and reason about the "shape" of the data that flows through your code. An elegant, and rapidly evolving language.
(clojure.spec-alpha2/def ::חודש
#{:חודש/ניסן
:חודש/אייר
:חודש/סיון
:חודש/תמוז
:חודש/אב
:חודש/אלול
:חודש/תשרי
:חודש/חשון
:חודש/מרחשון
:חודש/כסלו
:חודש/טבת
:חודש/שבט
:חודש/אדר
:חודש/אדר-ראשון
:חודש/אדר-שני})
(spec/defop days
[n]
`(spec/int-in ~n (inc ~n)))
(spec/def :חודש/ניסן
(days 30))
(spec/def :חודש/אייר
(days 29))
(spec/def :חודש/סיון
(days 30))
(spec/def :חודש/תמוז
(days 29))
(spec/def :חודש/אב
(days 30))
(spec/def :חודש/אלול
(days 29))
(spec/def :חודש/תשרי
(days 30))
(spec/def :חודש/חשון
(spec/or :min (days 29) :max (days 30)))
(spec/def :חודש/מרחשון
(spec/or :min (days 29) :max (days 30)))
(spec/def :חודש/כסלו
(spec/or :min (days 29) :max (days 30)))
(spec/def :חודש/טבת
(days 29))
(spec/def :חודש/שבט
(days 30))
(spec/def :חודש/אדר
(spec/or :min (days 29) :max (days 30)))
(spec/def :חודש/אדר-ראשון
(days 30))
(spec/def :חודש/אדר-שני
(days 29))
;; dev> (spec/describe :חודש/ניסן)
;; =>
;; (days 30)
;; dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment