FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactoring code examples · whitethief/clojure-through-code@cf5340a · GitHub

Repository navigation

Commit cf5340a

Browse files
Refactoring code examples
1 parent e014a73 commit cf5340a

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

‎src/clojure_through_code/functional_concepts.clj‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,14 @@ name-of-new-string
391391

392392
(:use 'clojure.string)
393393

394-
(defn- letter->clack [letter]
394+
(defn- letter->clack [alphabet letter]
395395
(get alphabet letter))
396396

397397
(def sentence "Codemotion Amsterdam")
398+
(def alphabet {"a" [001001] ,,,})
398399

399400
(let [words (clojure.string/upper-case sentence)]
400-
(map letter->clack (map str words)))
401+
(map #(letter->clack alphabet %) (map str words)
401402

402403

403404

@@ -412,7 +413,7 @@ name-of-new-string
412413
(defn twice [function-to-apply value]
413414
(function-to-apply (function-to-apply value)))
414415

415-
(twice #(+ % 3) 7)
416+
(twice #(+ % 3) 7)))
416417

417418

418419

@@ -435,12 +436,32 @@ name-of-new-string
435436

436437
(reduce + (range 1 10))
437438

438-
(reduce + '(1 2 3 4 5 6 7 8 9))
439+
(reduce + (quote (1 2 3 4 5 6 7 8 9)))
439440

440441
;; (range)
441442

442443
(take 10 (range))
443444

445+
(def sybol-name "value")
446+
447+
(defn function-name []
448+
(str "I am a function"))
449+
450+
(def function-name (fn [] (str "iaomdfiodjfod")))
451+
452+
(function-name)
453+
454+
(map (fn [number] (* number number)) [1 2 3 4])
455+
(map #(* %1 %2) [1 2 3 4] [3 4 5 6])
456+
457+
458+
459+
460+
461+
462+
463+
464+
444465

445466
;;;;;;;;;;;;;;;;;;
446467
;; Programming with functions
@@ -700,7 +721,7 @@ deref players
700721
;; reduces in depth
701722

702723
;; reduce takes 2 arguments, a function and a collections
703-
;; if val is supplied, returns the result of applying the function to the val and the first item in the collection, itterating through the colleciton
724+
;; if val is supplied, returns the result of applying the function to the val and the first item in the collection, itterating through the collection
704725

705726

706727

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL