forked from iloveponies/structured-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lein-repl-history
59 lines (59 loc) · 2.41 KB
/
.lein-repl-history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(defn old-book->new-book [book]
(let [new-books #{}
create-books (fn [[x]] (assoc new-books x))]
(map create-books book)))
exit
(contains? {:authors #{"Rich"}} :authors "Rich")
(contains? (:authors {:authors #{"Rich"}}) "Rich")
(:name {:name "The Shining" :authors #{"Stephen King"}})
(:name (:authors {:name "The Shining" :authors #{"Stephen King"}}))
(map #:name (:authors {:name "The Shining" :authors #{"Stephen King"}}))
(map :name (:authors {:name "The Shining" :authors #{"Stephen King"}}))
(:author {:author "test"})
(defn authors [books]
(let [book-author
(fn [book] (:authors book))]
(set (apply concat (map book-author books)))))
(defn all-author-names [books]
(let [author-names
(fn [author] (:name author))]
(set (apply concat (map author-names (authors books))))))
(authors [{:author {:name "Johnson"}}])
(defn author->string [author]
(let [author-name (:name author)
death-year (:death-year author)
birth-year (:birth-year author)]
(if (contains? author :birth-year)
(apply str author-name " (" birth-year " - " death-year ")")
(str author-name))))
(defn authors->string [authors]
(apply str (interpose ", " (set (apply concat (map authors->string authors))))))
(authors->string #{{:name "Dan" :birth-year "1991"} {:name "Charles"}})
(#{"Charles (1991 - )" "Dan (1954 -2001)"})
(println #{"Charles (1991 - )" "Dan (1954 -2001)"})
(str #{"Charles (1991 - )" "Dan (1954 -2001)"})
(apply str #{"Charles (1991 - )" "Dan (1954 -2001)"})
(apply str (interpose ", " #{"Charles (1991 - )" "Dan (1954 -2001)"}))
(= nil [])
(= [] [])
(= [] #{})
(= nil #{})
(empty? #{})
(defn has-author? [book author]
(contains? (:authors book) author))
(filter (has-author? "test") #{})
(filter (has-author? "test" x) #{})
(filter (has-author? "test" book) #{})
(filter (fn [book] (has-author? "test" book)) #{})
(filter (fn [book] (has-author? "test" book)) #{"test"})
(filter (fn [book] (has-author? "dan" book)) #{{:title "test" :authors "dan"}})
(filter #((has-author? "dan" %)) #{{:title "test" :authors "dan"}})
(filter #( (has-author? "dan" %)) #{{:title "test" :authors "dan"}})
(filter #((has-author? "dan" %1)) #{{:title "test" :authors "dan"}})
(contains? (:name "test") {:name "test})
)
(contains? (:name "test") {:name "test"})
(contains? "test" {:name "test"})
(contains? {:name "test"} (:name "test"))
(contains? (:name "test") {:name "test"})
(contains? {:name "test"} "test")