Liking cljdoc? Tell your friends :D

shape-shifter

Clojars Project

Transforms a string pattern into clojure spec.

Patterns

Inspired by grape pattern system. All supported patterns can be found here and also can be expanded.

Expand patterns

(require '[shape-shifter.core :refer [pattern->spec *wildcards*]])

(def spec (binding [*wildcards* (merge *wildcards* {"$banana" #{"banana"}})]
                 (pattern->spec "$banana")))
(s/valid? spec "banana")

Examples

Simple form

(require '[shape-shifter.core :refer [pattern->spec]])
(def spec (pattern->spec "($& read-string $&)"))
(s/valid? spec '(-> "1" read-string inc)) => true

Nested forms

(require '[shape-shifter.core :refer [pattern->spec]])
(def spec (pattern->spec "(-> $string read-string (+ $number))"))
(s/valid? spec '(-> "1" read-string (+ 10))) => true

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close