[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Enhance seq-min and seq-max
From: |
Nicolas Petton |
Subject: |
Re: Enhance seq-min and seq-max |
Date: |
Sun, 16 Jun 2019 22:11:01 +0200 |
Michael Heerdegen <address@hidden> writes:
> Michael Heerdegen <address@hidden> writes:
Hi Michael,
>> Like this, maybe?
I like the idea! In addition to documentation, could you also add
unit tests? (for seq.el, I like when my unit tests test multiple
sequence types).
I left some comments below.
> + (if predicate
^^^^^^^^^
What if `predicate' is nil but `key' is non-nil?
> + (if key
> + (let ((first (car sequence)))
^^^
You cannot use `car' here
> + (cdr (seq-reduce
> + (lambda (key-x-and-x y)
> + (let ((key-y-and-y (cons (funcall key y) y)))
> + (if (funcall predicate (car key-y-and-y) (car
> key-x-and-x))
> + key-y-and-y
> + key-x-and-x)))
> + (cdr sequence)
^^^
You cannot use `cdr' either
> + (cons (funcall key first) first))))
> + (seq-reduce
> + (lambda (x y) (if (funcall predicate y x) y x))
> + (cdr sequence) (car sequence)))
> + (apply #'min (seq-into sequence 'list))))
^^^^^^^^^^^^^^^^^^^^^^^
I think your version of `seq-min' will break when
`predicate' is used for all sequence types but lists,
since you don't convert the sequence, but use `car'
and `cdr'.
Thanks!
Nico
signature.asc
Description: PGP signature
- Emacs 26.2.90 is out!, Nicolas Petton, 2019/06/12
- Re: Emacs 26.2.90 is out!, Nicolas Petton, 2019/06/12
- Re: Emacs 26.2.90 is out!, Phillip Lord, 2019/06/13
- stream.el (was: Emacs 26.2.90 is out!), Michael Heerdegen, 2019/06/13
- Re: Enhance seq-min and seq-max, Michael Heerdegen, 2019/06/15
- Re: Enhance seq-min and seq-max,
Nicolas Petton <=
- Re: Enhance seq-min and seq-max, Michael Heerdegen, 2019/06/16
- Re: Enhance seq-min and seq-max, Nicolas Petton, 2019/06/17
- Re: Enhance seq-min and seq-max, Michael Heerdegen, 2019/06/25
- Re: Enhance seq-min and seq-max, Nicolas Petton, 2019/06/26