I personally prefer multimethods, generally speaking—I think they feel more 
idiomatic. Although it does depend on the context of what you’re doing. In some 
cases a protocol may be the correct choice. Here the multimethod seems fine.


> On May 14, 2015, at 16:34, Jason Marmon <jtmar...@gmail.com> wrote:
> 
> I'm working on a tool to orchestrate the migration from mongodb to datomic, 
> and i'm looking for a bit of design feedback as i'm new to clojure. 
> 
> 
> 
> The user needs to provide functions that transform mongodb documents into 
> datomic txes. Do y'all prefer the top or bottom style, or think there's a 
> different way to implement this design that might be better?
> 
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> ;; Multimethod for transforming data based on the name of the source mongodb 
> collection 
> (defmulti transform identity)
>  
> (defmethod transform "events" [data]
>    ;; do something with data
>  )
>  
> (defmethod transform "users" [data]
>    ;; do something with data
>  )
>  
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>  
> (defprotocol Collection-Transformer
>    (transform [mongo-db document]))
>  
> (def user-transformer
>  (reify Collection-Transformer
>   (transform [m d] "do stuff")))
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> <http://groups.google.com/group/clojure?hl=en>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to