DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Frequent Used Functions in Clojure


  • (type ...): get the data type of ...;

  • (apply + [1 2 3]) <=> (+ 1 2 3), but not equals to (+ [1 2 3]), p65;

  • (map f [a b c]) <=> ((f a) (f b) (f c));

(map f [a b c] [x y z]) <=> ((f a x) (f b y) (f c z));

(type (map + [1 2 3] [10 20 30])) => clojure.lang.LazySeq, p61;

  • (conj [1 2] 3) => [1 2 3];

(conj [1 2] [3 4]) => [1 2 [3 4]];

(conj [1 2] [3 4] [5 6]) => [1 2 [3 4] [5 6]];

  • (into [1 2] 3) => exception;

(into [1 2] [3]) => [1 2 3];

(into [1 2] [3 4] [5]) => exception;

  • (drop 1 [1 2 3]) => (2 3);

(drop 2 [1 2 3]) => (3);

(type (drop 2 [1 2 3])) => clojure.lang.LazySeq;

  • (take-nth 2 (range 10)) => (0 2 4 6 8)

(take-nth 3 (range 10)) => (0 3 6 9) (take-nth 7 (range 10)) => (0 7) (take-nth 9 (range 10)) => (0 9)

(take-nth 2 #{3 5 7 9}) => (3 7) (take-nth 2 {:a 3 :b 5 :c 7 :d 9}) => ([:a 3] [:c 7])

(type (take-nth 2 {:a 3 :b 5 :c 7 :d 9})) => clojure.lang.LazySeq



Published

Sep 17, 2013

Last Updated

Sep 17, 2013

Category

Tech

Tags

  • clojure 26

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor