@@ -373,8 +373,9 @@ Functions that manipulate and compose other functions.
373373* [ ` -juxt ` ] ( #-juxt-rest-fns ) ` (&rest fns) `
374374* [ ` -compose ` ] ( #-compose-rest-fns ) ` (&rest fns) `
375375* [ ` -applify ` ] ( #-applify-fn ) ` (fn) `
376- * [ ` -on ` ] ( #-on-operator-transformer ) ` (operator transformer) `
377- * [ ` -flip ` ] ( #-flip-func ) ` (func) `
376+ * [ ` -on ` ] ( #-on-op-trans ) ` (op trans) `
377+ * [ ` -flip ` ] ( #-flip-fn ) ` (fn) `
378+ * [ ` -rotate-args ` ] ( #-rotate-args-n-fn ) ` (n fn) `
378379* [ ` -const ` ] ( #-const-c ) ` (c) `
379380* [ ` -cut ` ] ( #-cut-rest-params ) ` (&rest params) `
380381* [ ` -not ` ] ( #-not-pred ) ` (pred) `
@@ -1193,7 +1194,7 @@ Return the smallest value from `list` of numbers or markers.
11931194Take a comparison function ` comparator ` and a ` list ` and return
11941195the least element of the list by the comparison function.
11951196
1196- See also combinator [ ` -on ` ] ( #-on-operator-transformer ) which can transform the values before
1197+ See also combinator [ ` -on ` ] ( #-on-op-trans ) which can transform the values before
11971198comparing them.
11981199
11991200``` el
@@ -1217,7 +1218,7 @@ Return the largest value from `list` of numbers or markers.
12171218Take a comparison function ` comparator ` and a ` list ` and return
12181219the greatest element of the list by the comparison function.
12191220
1220- See also combinator [ ` -on ` ] ( #-on-operator-transformer ) which can transform the values before
1221+ See also combinator [ ` -on ` ] ( #-on-op-trans ) which can transform the values before
12211222comparing them.
12221223
12231224``` el
@@ -2892,30 +2893,56 @@ taking 1 argument which is a list of `n` arguments.
28922893(funcall (-applify #'<) '(3 6)) ;; => t
28932894```
28942895
2895- #### -on ` (operator transformer ) `
2896+ #### -on ` (op trans ) `
28962897
2897- Return a function of two arguments that first applies
2898- ` transformer ` to each of them and then applies ` operator ` on the
2899- results (in the same order).
2898+ Return a function that calls ` trans ` on each arg and ` op ` on the results.
2899+ The returned function takes a variable number of arguments, calls
2900+ the function ` trans ` on each one in turn, and then passes those
2901+ results as the list of arguments to ` op ` , in the same order.
29002902
2901- In types: (b -> b -> c) -> (a -> b) -> a -> a -> c
2903+ For example, the following pairs of expressions are morally
2904+ equivalent:
2905+
2906+ (funcall (-on #'+ #'1+) 1 2 3) = (+ (1+ 1) (1+ 2) (1+ 3))
2907+ (funcall (-on #'+ #'1+)) = (+)
29022908
29032909``` el
2904- (-sort (-on '< 'length) '((1 2 3) (1) (1 2))) ;; => ((1) (1 2) (1 2 3))
2905- (-min-by (-on '> 'length) '((1 2 3) (4) (1 2))) ;; => (4)
2906- (-min-by (-on 'string-lessp 'number-to-string ) '(2 100 22)) ;; => 22
2910+ (-sort (-on # '< # 'length) '((1 2 3) (1) (1 2))) ;; => ((1) (1 2) (1 2 3))
2911+ (funcall (-on #'min #'string-to-number) "22" "2" "1" "12") ;; => 1
2912+ (-min-by (-on #'> #'length ) '((1 2 3) (4) (1 2))) ;; => (4)
29072913```
29082914
2909- #### -flip ` (func) `
2915+ #### -flip ` (fn) `
2916+
2917+ Return a function that calls ` fn ` with its arguments reversed.
2918+ The returned function takes the same number of arguments as ` fn ` .
2919+
2920+ For example, the following two expressions are morally
2921+ equivalent:
29102922
2911- Swap the order of arguments for binary function ` func ` .
2923+ (funcall (-flip #'-) 1 2) = (- 2 1)
29122924
2913- In types: (a -> b -> c) -> b -> a -> c
2925+ See also: [ ` -rotate-args ` ] ( #-rotate-args-n-fn ) .
29142926
29152927``` el
2916- (funcall (-flip '<) 2 1) ;; => t
2917- (funcall (-flip '-) 3 8) ;; => 5
2918- (-sort (-flip '<) '(4 3 6 1)) ;; => (6 4 3 1)
2928+ (-sort (-flip #'<) '(4 3 6 1)) ;; => (6 4 3 1)
2929+ (funcall (-flip #'-) 3 2 1 10) ;; => 4
2930+ (funcall (-flip #'1+) 1) ;; => 2
2931+ ```
2932+
2933+ #### -rotate-args ` (n fn) `
2934+
2935+ Return a function that calls ` fn ` with args rotated ` n ` places to the right.
2936+ The returned function takes the same number of arguments as ` fn ` ,
2937+ rotates the list of arguments ` n ` places to the right (left if ` n ` is
2938+ negative) just like [ ` -rotate ` ] ( #-rotate-n-list ) , and applies ` fn ` to the result.
2939+
2940+ See also: [ ` -flip ` ] ( #-flip-fn ) .
2941+
2942+ ``` el
2943+ (funcall (-rotate-args -1 #'list) 1 2 3 4) ;; => (2 3 4 1)
2944+ (funcall (-rotate-args 1 #'-) 1 10 100) ;; => 89
2945+ (funcall (-rotate-args 2 #'list) 3 4 5 1 2) ;; => (1 2 3 4 5)
29192946```
29202947
29212948#### -const ` (c) `
@@ -2926,8 +2953,8 @@ In types: a -> b -> a
29262953
29272954``` el
29282955(funcall (-const 2) 1 3 "foo") ;; => 2
2929- (-map (-const 1) '("a" "b" "c" "d")) ;; => (1 1 1 1)
2930- (-sum (-map (-const 1) '("a" "b" "c" "d"))) ;; => 4
2956+ (mapcar (-const 1) '("a" "b" "c" "d")) ;; => (1 1 1 1)
2957+ (-sum (mapcar (-const 1) '("a" "b" "c" "d"))) ;; => 4
29312958```
29322959
29332960#### -cut ` (&rest params) `
@@ -2945,40 +2972,50 @@ See `srfi-26` for detailed description.
29452972
29462973#### -not ` (pred) `
29472974
2948- Take a unary predicate ` pred ` and return a unary predicate
2949- that returns t if ` pred ` returns nil and nil if ` pred ` returns
2950- non-nil.
2975+ Return a predicate that negates the result of ` pred ` .
2976+ The returned predicate passes its arguments to ` pred ` . If ` pred `
2977+ returns nil, the result is non-nil; otherwise the result is nil.
2978+
2979+ See also: [ ` -andfn ` ] ( #-andfn-rest-preds ) and [ ` -orfn ` ] ( #-orfn-rest-preds ) .
29512980
29522981``` el
2953- (funcall (-not 'even?) 5) ;; => t
2954- (-filter (-not (-partial '< 4)) '(1 2 3 4 5 6 7 8)) ;; => (1 2 3 4)
2982+ (funcall (-not #'numberp) "5") ;; => t
2983+ (-sort (-not #'<) '(5 2 1 0 6)) ;; => (6 5 2 1 0)
2984+ (-filter (-not (-partial #'< 4)) '(1 2 3 4 5 6 7 8)) ;; => (1 2 3 4)
29552985```
29562986
29572987#### -orfn ` (&rest preds) `
29582988
2959- Take list of unary predicates ` preds ` and return a unary
2960- predicate with argument x that returns non-nil if at least one of
2961- the ` preds ` returns non-nil on x.
2989+ Return a predicate that returns the first non-nil result of ` preds ` .
2990+ The returned predicate takes a variable number of arguments,
2991+ passes them to each predicate in ` preds ` in turn until one of them
2992+ returns non-nil, and returns that non-nil result without calling
2993+ the remaining ` preds ` . If all ` preds ` return nil, or if no ` preds ` are
2994+ given, the returned predicate returns nil.
29622995
2963- In types : [ a -> Bool ] -> a -> Bool
2996+ See also : [ ` -andfn ` ] ( #-andfn-rest-preds ) and [ ` -not ` ] ( #-not-pred ) .
29642997
29652998``` el
2966- (-filter (-orfn 'even? (-partial (-flip '<) 5)) '(1 2 3 4 5 6 7 8 9 10)) ;; => (1 2 3 4 6 8 10)
2967- (funcall (-orfn 'stringp 'even?) "foo") ;; => t
2999+ (-filter (-orfn #'natnump #'booleanp) '(1 nil "a" -4 b c t)) ;; => (1 nil t)
3000+ (funcall (-orfn #'symbolp (-cut string-match-p "x" <>)) "axe") ;; => 1
3001+ (funcall (-orfn #'= #'+) 1 1) ;; => t
29683002```
29693003
29703004#### -andfn ` (&rest preds) `
29713005
2972- Take list of unary predicates ` preds ` and return a unary
2973- predicate with argument x that returns non-nil if all of the
2974- ` preds ` returns non-nil on x.
3006+ Return a predicate that returns non-nil if all ` preds ` do so.
3007+ The returned predicate ` p ` takes a variable number of arguments and
3008+ passes them to each predicate in ` preds ` in turn. If any one of
3009+ ` preds ` returns nil, ` p ` also returns nil without calling the
3010+ remaining ` preds ` . If all ` preds ` return non-nil, ` p ` returns the last
3011+ such value. If no ` preds ` are given, ` p ` always returns non-nil.
29753012
2976- In types : [ a -> Bool ] -> a -> Bool
3013+ See also : [ ` -orfn ` ] ( #-orfn-rest-preds ) and [ ` -not ` ] ( #-not-pred ) .
29773014
29783015``` el
2979- (funcall (-andfn (-cut < <> 10) 'even?) 6) ;; => t
2980- (funcall (-andfn (-cut < <> 10) 'even?) 12) ;; => nil
2981- (-filter (-andfn (-not 'even?) (-cut >= 5 <>)) '(1 2 3 4 5 6 7 8 9 10)) ;; => (1 3 5)
3016+ (-filter (-andfn #'numberp (-cut < <> 5)) '(a 1 b 6 c 2)) ;; => (1 2)
3017+ (mapcar (-andfn #'numberp #'1+) '(a 1 b 6)) ;; => ( nil 2 nil 7)
3018+ (funcall (-andfn #'= #'+) 1 1) ;; => 2
29823019```
29833020
29843021#### -iteratefn ` (fn n) `
0 commit comments