You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.adoc
+23-15
Original file line number
Diff line number
Diff line change
@@ -1511,25 +1511,23 @@ more than one form.
1511
1511
(* % 2))
1512
1512
----
1513
1513
1514
-
=== `complement` [[complement]]
1514
+
=== Anonymous Functions vs `complement`, `comp` and `partial`
1515
1515
1516
-
Favor the use of `complement` versus the use of an anonymous function.
1516
+
Prefer anonymous functions over `complement`, `comp` and `partial`, as this results
1517
+
in simpler code most of the time.footnote:[You can read more on the subject https://ask.clojure.org/index.php/8373/when-should-prefer-comp-and-partial-to-anonymous-functions[here].]
1518
+
1519
+
==== `complement` [[complement]]
1517
1520
1518
1521
[source,clojure]
1519
1522
----
1520
1523
;; good
1521
-
(filter (complement some-pred?) coll)
1522
-
1523
-
;; bad
1524
1524
(filter #(not (some-pred? %)) coll)
1525
-
----
1526
-
1527
-
This rule should obviously be ignored if the complementing predicate
1528
-
exists in the form of a separate function (e.g. `even?` and `odd?`).
1529
1525
1530
-
=== `comp` [[comp]]
1526
+
;; okish
1527
+
(filter (complement some-pred?) coll)
1528
+
----
1531
1529
1532
-
Favor `comp` over anonymous functions for function composition.
1530
+
==== `comp` [[comp]]
1533
1531
1534
1532
[source,clojure]
1535
1533
----
@@ -1538,20 +1536,30 @@ Favor `comp` over anonymous functions for function composition.
1538
1536
;; good
1539
1537
(map #(str/capitalize (str/trim %)) ["top " " test "])
1540
1538
1541
-
;; better
1539
+
;; okish
1542
1540
(map (comp str/capitalize str/trim) ["top " " test "])
1543
1541
----
1544
1542
1545
-
=== `partial` [[partial]]
1543
+
`comp` is quite useful when composing transducer chains, though.
0 commit comments