Skip to content

Commit a1502fb

Browse files
committed
Align and do not use default with apply min
Since (apply min <any-coll> 0) is always 0
1 parent 247c15b commit a1502fb

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Chapter04/Activity4.01/src/packt-clj/game_values.clj

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns packt-clj.game-values)
22

3-
43
(def game-users
54
[{:id 9342
65
:username "speedy"
@@ -63,22 +62,19 @@
6362
:experience-level 8
6463
:status :active}])
6564

66-
6765
(defn max-value-by-status [field status users]
68-
(->>
69-
users
70-
;; step 1: use filter to only keep users who
71-
;; have the status we are looking for
72-
(filter #(= (:status %) status))
73-
;; step 2: field is a keyword, so we can use it as
74-
;; a function when calling map.
75-
(map field)
76-
;; step 3: use the apply max pattern, with a default
77-
(apply max 0)))
66+
(->> users
67+
;; step 1: use filter to only keep users who
68+
;; have the status we are looking for
69+
(filter #(= (:status %) status))
70+
;; step 2: field is a keyword, so we can use it as
71+
;; a function when calling map.
72+
(map field)
73+
;; step 3: use the apply max pattern, with a default
74+
(apply max 0)))
7875

7976
(defn min-value-by-status [field status users]
80-
(->>
81-
users
82-
(filter #(= (:status %) status))
83-
(map field)
84-
(apply min 0)))
77+
(->> users
78+
(filter #(= (:status %) status))
79+
(map field)
80+
(apply min))) ;; do not use a default, (min '()) returns nil

0 commit comments

Comments
 (0)