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. 24
      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 elements of `list` using `comparator` relation, yielding a
permutation vector such that applying this permutation to `list`
sorts it in ascending order.
Grade elements of `list` using `comparator` relation.
This yields a permutation vector such that applying this
permutation to `list` sorts it in ascending order.
```el
(-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)
(-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)
```
#### -grade-down `(comparator list)`
Grade elements of `list` using `comparator` relation, yielding a
permutation vector such that applying this permutation to `list`
sorts it in descending order.
Grade elements of `list` using `comparator` relation.
This yields a permutation vector such that applying this
permutation to `list` sorts it in descending order.
```el
(-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)
(-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)
```

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

@ -2405,17 +2405,17 @@ predicate @var{pred}, in ascending order.
@anchor{-grade-up}
@defun -grade-up (comparator list)
Grade elements of @var{list} using @var{comparator} relation, yielding a
permutation vector such that applying this permutation to @var{list}
sorts it in ascending order.
Grade elements of @var{list} using @var{comparator} relation.
This yields a permutation vector such that applying this
permutation to @var{list} sorts it in ascending order.
@example
@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)
@end 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)
@end group
@end example
@ -2423,17 +2423,17 @@ sorts it in ascending order.
@anchor{-grade-down}
@defun -grade-down (comparator list)
Grade elements of @var{list} using @var{comparator} relation, yielding a
permutation vector such that applying this permutation to @var{list}
sorts it in descending order.
Grade elements of @var{list} using @var{comparator} relation.
This yields a permutation vector such that applying this
permutation to @var{list} sorts it in descending order.
@example
@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)
@end 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)
@end group
@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))
(defexamples -grade-up
(-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))
(-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))
(defexamples -grade-down
(-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)))
(-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)))
(def-example-group "Set operations"
"Operations pretending lists are sets."

Loading…
Cancel
Save