Skip to content

realyze/faustini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Faustini

Clojars Project

Circle CI

It maps things to other things! Which is particularly useful if you have, say, some web services that you get JSON data from and you want to store them in your very own app data format.

Steps:

  1. Describe the mapping to Faustini (via define-mapping).
  2. Pass items to the mapping function and get items in your app format.
  3. ...
  4. PROFIT!

Documentation

...with a real world use case scenario is here. It is generated from the tests using midje-doc so if the CircleCI badge is green, it should be up-to-date.

Simple (And Totally Contrived) Example

(require '[faustini.core :refer [define-mapping ==> =?>]])

(def foo {:item1 [{:item2 "value!"}]})

(define-mapping my-map
  [:remapped-entry ==> :item1 0 :item2])

(my-map foo)
;; {:remapped-entry "value!"}

More complex example

(require '[faustini.core :refer [define-mapping ==> =?>]])



(def foo {:item-1-1 [{:item-1-2 "snickers!"}]
          :item-2-1 {:item-2-2 "foobar!"
                     :item-2-3 "barbar!"}})

(def bar {:item-1-1 [{:item-1-2 "mars!"}]
          :item-2-1 {:item-2-2 "foobar!"
                     :item-2-3 "barbar!"}})


(define-mapping my-map
  [[:item-1-1 0 :item-1-2] =?> [:match-set #{"snickers!"}
                                  [:remapped-entry ==> :item-2-1 :item-2-2]
                                  [:remapped-entry-2 ==> :item-1-1 0 :item-1-2]

                                :match-set #{"mars!" "twix!"}
                                  [:remapped-entry ==> :item-2-1 :item-2-2]
                                  [:remapped-entry-2 ==> :item-2-1 :item-2-3]]])

(my-map foo)
;; {:remapped-entry "foobar!"
;;  :remapped-entry-2 "snickers!"}

(my-map bar)
;; {:remapped-entry "foobar!"
;;  :remapped-entry-2 "barbar!"}

License

Copyright © 2014 Tomas Brambora, Salsita, l.t.d.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Behold! It maps things to...other things!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published