Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def inc-coll (partial map inc))
- ;;#'user/inc-coll
- (inc-coll [4 5 6])
- ;;(5 6 7)
- (def inc-coll-coll (partial map inc-coll))
- ;;#'user/inc-coll-coll
- (inc-coll-coll [[1] [2]])
- ;;((2) (3))
- (inc-coll-coll [[1] 3])
- ;;IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:542)
- (defn inc2 [n] (cond (sequential? n) (inc-coll n) (number? n) (inc n) :else n))
- ;;#'user/inc2
- (def inc-coll-coll (partial map inc2))
- ;;#'user/inc-coll-coll
- (inc-coll-coll [[1] [2]])
- ;;((2) (3))
- (inc-coll-coll [[1] [2] 3])
- ;;((2) (3) 4)
- ;;without conditionals
- (defmulti inc2 class)
- ;;#'user/inc2
- (defmethod inc2 Number [n] (inc n))
- ;#object[clojure.lang.MultiFn 0x155f5b43 "clojure.lang.MultiFn@155f5b43"]
- (inc2 10)
- ;11
- (defmethod inc2 clojure.lang.Sequential [c] (map inc c))
- ;;#object[clojure.lang.MultiFn 0x155f5b43 "clojure.lang.MultiFn@155f5b43"]
- (inc2 [1])
- ;(2)
- (inc-coll-coll [[1] [2] 3])
- ;((2) (3) 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement