fix mistakes 1/x
This commit is contained in:
+16
-5
@@ -259,8 +259,7 @@ nil ; => nil (Null/Nothing)
|
||||
|
||||
(swap! counter inc) ; => 1
|
||||
(swap! counter + 5) ; => 6
|
||||
(dosync
|
||||
(reset! counter 0)) ; => 0
|
||||
(reset! counter 0) ; => 0
|
||||
|
||||
;; --- 14. Java Interop ---
|
||||
|
||||
@@ -317,9 +316,21 @@ nil ; => nil (Null/Nothing)
|
||||
|
||||
;; --- 18. Common Patterns ---
|
||||
|
||||
;; Compose functions
|
||||
(defn make-upper [s] (str/upper-case s))
|
||||
(def make-upper-lower (comp str/lower-case str/upper-case)) ; => #object[clojure.core$comp$fn ...]
|
||||
;; Compose functions — comp reads right-to-left (like math)
|
||||
;; Example: slugify — find word chunks, lowercase, join with dashes
|
||||
(def slugify (comp #(str/join "-" %) #(mapv str/lower-case %) #(re-seq #"\S+" %)))
|
||||
|
||||
;; Usage
|
||||
(slugify " Hello World ") ; => "hello-world"
|
||||
(slugify "Foo Bar Baz") ; => "foo-bar-baz"
|
||||
(slugify " Hello World ") ; => "hello-world"
|
||||
|
||||
;; Another: trim then uppercase
|
||||
(def trim->upper (comp str/upper-case str/trim))
|
||||
|
||||
;; Usage
|
||||
(trim->upper " hello ") ; => "HELLO"
|
||||
(trim->upper " Clojure is fun ") ; => "CLOJURE IS FUN"
|
||||
|
||||
;; Partial application
|
||||
|
||||
|
||||
Reference in New Issue
Block a user