Merge pull request #235

master
Basil L. Contovounesios 5 years ago
commit f97563436d
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 20
      README.md
  2. 28
      dash.el
  3. 20
      dash.texi
  4. 8
      dev/examples.el

@ -1624,24 +1624,24 @@ predicate `pred`, in ascending order.
#### -grade-up `(comparator list)` #### -grade-up `(comparator list)`
Grade elements of `list` using `comparator` relation, yielding a Grade elements of `list` using `comparator` relation.
permutation vector such that applying this permutation to `list` This yields a permutation vector such that applying this
sorts it in ascending order. permutation to `list` sorts it in ascending order.
```el ```el
(-grade-up '< '(3 1 4 2 1 3 3)) ;; => '(1 4 3 0 5 6 2) (-grade-up #'< '(3 1 4 2 1 3 3)) ;; => '(1 4 3 0 5 6 2)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up '< l) l)) ;; => '(1 1 2 3 3 3 4) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up #'< l) l)) ;; => '(1 1 2 3 3 3 4)
``` ```
#### -grade-down `(comparator list)` #### -grade-down `(comparator list)`
Grade elements of `list` using `comparator` relation, yielding a Grade elements of `list` using `comparator` relation.
permutation vector such that applying this permutation to `list` This yields a permutation vector such that applying this
sorts it in descending order. permutation to `list` sorts it in descending order.
```el ```el
(-grade-down '< '(3 1 4 2 1 3 3)) ;; => '(2 0 5 6 3 1 4) (-grade-down #'< '(3 1 4 2 1 3 3)) ;; => '(2 0 5 6 3 1 4)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down '< l) l)) ;; => '(4 3 3 3 2 1 1) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down #'< l) l)) ;; => '(4 3 3 3 2 1 1)
``` ```

@ -1755,24 +1755,20 @@ Note: `it' need not be used in each form."
it)) it))
(defun -grade-up (comparator list) (defun -grade-up (comparator list)
"Grade elements of LIST using COMPARATOR relation, yielding a "Grade elements of LIST using COMPARATOR relation.
permutation vector such that applying this permutation to LIST This yields a permutation vector such that applying this
sorts it in ascending order." permutation to LIST sorts it in ascending order."
;; ugly hack to "fix" lack of lexical scope (->> (--map-indexed (cons it it-index) list)
(let ((comp `(lambda (it other) (funcall ',comparator (car it) (car other))))) (-sort (lambda (it other) (funcall comparator (car it) (car other))))
(->> (--map-indexed (cons it it-index) list) (mapcar #'cdr)))
(-sort comp)
(-map 'cdr))))
(defun -grade-down (comparator list) (defun -grade-down (comparator list)
"Grade elements of LIST using COMPARATOR relation, yielding a "Grade elements of LIST using COMPARATOR relation.
permutation vector such that applying this permutation to LIST This yields a permutation vector such that applying this
sorts it in descending order." permutation to LIST sorts it in descending order."
;; ugly hack to "fix" lack of lexical scope (->> (--map-indexed (cons it it-index) list)
(let ((comp `(lambda (it other) (funcall ',comparator (car other) (car it))))) (-sort (lambda (it other) (funcall comparator (car other) (car it))))
(->> (--map-indexed (cons it it-index) list) (mapcar #'cdr)))
(-sort comp)
(-map 'cdr))))
(defvar dash--source-counter 0 (defvar dash--source-counter 0
"Monotonic counter for generated symbols.") "Monotonic counter for generated symbols.")

@ -2405,17 +2405,17 @@ predicate @var{pred}, in ascending order.
@anchor{-grade-up} @anchor{-grade-up}
@defun -grade-up (comparator list) @defun -grade-up (comparator list)
Grade elements of @var{list} using @var{comparator} relation, yielding a Grade elements of @var{list} using @var{comparator} relation.
permutation vector such that applying this permutation to @var{list} This yields a permutation vector such that applying this
sorts it in ascending order. permutation to @var{list} sorts it in ascending order.
@example @example
@group @group
(-grade-up '< '(3 1 4 2 1 3 3)) (-grade-up #'< '(3 1 4 2 1 3 3))
@result{} '(1 4 3 0 5 6 2) @result{} '(1 4 3 0 5 6 2)
@end group @end group
@group @group
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up '< l) l)) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up #'< l) l))
@result{} '(1 1 2 3 3 3 4) @result{} '(1 1 2 3 3 3 4)
@end group @end group
@end example @end example
@ -2423,17 +2423,17 @@ sorts it in ascending order.
@anchor{-grade-down} @anchor{-grade-down}
@defun -grade-down (comparator list) @defun -grade-down (comparator list)
Grade elements of @var{list} using @var{comparator} relation, yielding a Grade elements of @var{list} using @var{comparator} relation.
permutation vector such that applying this permutation to @var{list} This yields a permutation vector such that applying this
sorts it in descending order. permutation to @var{list} sorts it in descending order.
@example @example
@group @group
(-grade-down '< '(3 1 4 2 1 3 3)) (-grade-down #'< '(3 1 4 2 1 3 3))
@result{} '(2 0 5 6 3 1 4) @result{} '(2 0 5 6 3 1 4)
@end group @end group
@group @group
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down '< l) l)) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down #'< l) l))
@result{} '(4 3 3 3 2 1 1) @result{} '(4 3 3 3 2 1 1)
@end group @end group
@end example @end example

@ -776,12 +776,12 @@ value rather than consuming a list to produce a single value."
(-find-indices (-partial 'string-lessp "baz") '("bar" "foo" "baz")) => '(1)) (-find-indices (-partial 'string-lessp "baz") '("bar" "foo" "baz")) => '(1))
(defexamples -grade-up (defexamples -grade-up
(-grade-up '< '(3 1 4 2 1 3 3)) => '(1 4 3 0 5 6 2) (-grade-up #'< '(3 1 4 2 1 3 3)) => '(1 4 3 0 5 6 2)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up '< l) l)) => '(1 1 2 3 3 3 4)) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up #'< l) l)) => '(1 1 2 3 3 3 4))
(defexamples -grade-down (defexamples -grade-down
(-grade-down '< '(3 1 4 2 1 3 3)) => '(2 0 5 6 3 1 4) (-grade-down #'< '(3 1 4 2 1 3 3)) => '(2 0 5 6 3 1 4)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down '< l) l)) => '(4 3 3 3 2 1 1))) (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down #'< l) l)) => '(4 3 3 3 2 1 1)))
(def-example-group "Set operations" (def-example-group "Set operations"
"Operations pretending lists are sets." "Operations pretending lists are sets."

Loading…
Cancel
Save