squest / clojure-tutorial

Clojure tutorial in Bahasa Indonesia (video version)
Eclipse Public License 1.0
46 stars 7 forks source link

Must know functions in Clojure @aisyahgunung #4

Open squest opened 8 years ago

squest commented 8 years ago

ffirst, map-indexed, keep, keep-indexed, (using #{} as lambda function in map/some/filter/remove), group-by, partition, partition-by, get-in, assoc-in, update-in, split-at, split-with, take-while, drop-while, drop-last, interleave, interpose, comp, juxt, partial, complement, zipmap, mapcat, take-last, reductions, merge, merge-with, select-keys, (map destructuring {:keys [some-key another-key]})

codxse commented 8 years ago

loop sama for segitu gak ngaruhnya da di clojure??

squest commented 8 years ago

Loop hampir ga pernah dipake di realworld programming. For clojure beda total sama for yg ada, for clojure itu kayak list-comprehension di haskell or python, tapi much more powerful.

Btw, loop & for itu macros bukan functions.

squest commented 8 years ago

Based on 1 project gue yang lumayan kompleks, jumlah keywords yang paling banyak muncul di app gue sbb (sesuai urutan yang paling sering)

defn, let, dissoc, if, merge, when-let, into, if-let, doseq, assoc, dosync, every?, into, str, recur, nil?, mapv, fn, defrecord, select-keys, read-string, get-in, contains?, map, set, future, update-in, try, catch, ref-set, some, when, and, or...

Ya kira2x ini yang paling sering muncul di satu sample app gue yang lumayan kompleks.

Ini kode utk baca files di app + ngitung kemunculan keywords.

(defn read-those []
  (->> (for [file files]
         (slurp (str dir file)))
       (apply concat)
       (apply str)
       (cs/split-lines)
       (mapcat #(cs/split % #" "))
       frequencies
       (sort-by val)
       (filter #(= \( (ffirst %)))))

;; dir is the directory
;; files is a list of files in that directory or sub-dirs

Elo bisa liat cara ngoding di clojure stylenya gitu, bisa langsung satu jalan with ->> macro