Muotti
Noun.
- mould/mold (hollow form or matrix for shaping a fluid or plastic substance)
- cast (mould used to make cast objects)
- die
- form (thing that gives shape to other things as in a mold)
(source: https://en.wiktionary.org/wiki/muotti)
Muotti is a graph based value transformer library which aims to solve value transformation by utilizing a digraph of known transformations to produce a transformer chain which is then used to perform the actual transformation.
Given a map of adjacencies - that is, edges of a graph - with validation and transformer functions:
(require '[muotti.core :as muotti])
(def config {:transformations {[:keyword :string] {:validator keyword?
:transformer name}
[:string :number] {:validator string?
:transformer parse-long}
[:string :boolean] {:validator string?
:transformer boolean}
[:number :string] {:validator number?
:transformer str}}})
a transformer can be created:
(def t (muotti/->transformer transformations))
which is then immediately usable for transforming values:
(muotti/transform t :keyword :number :123)
; => 123
(muotti/transform t :number :keyword 123)
; => :123
Unresolvable transformations return a special value:
(muotti/transform t :keyword :double :3.14)
; => ::unknown-path
Transformer chain validation errors also return a special value:
(def broken-adjacency {[:a :b] {:validator keyword?
:transformer str})
(def t2 (->transformer broken-adjacency))
(muotti/transform t2 :a :b "not a number")
; => ::invalid-value
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close