emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ELPA] New package: find-dups


From: Andreas Politz
Subject: Re: [ELPA] New package: find-dups
Date: Thu, 12 Oct 2017 10:37:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

What you seem to be doing is something like this (minus equal vs eq).

#+BEGIN_SRC emacs-lisp
  (defun partition-by (s &rest fns)
    "Partition sequence S by some function F.

  Partition S using a equivalence relation R constructed by F, such
  that for all x,y ∈ S

       (x, y) ∈ R ⇔ f(x) = f(y) .

  If GS is non-nil, it should be a list of functions acting as necessary
  conditions, such that for all x,y ∈ S and g₁̣,..,gₙ ∈ GS:

       g₁(x) = g₁(y)  ⇐ ... ⇐ gₙ(x) = gₙ(y) ⇐ f(x) = f(y)

  The idea is that the functions in GS may be computed more efficiently
  than F and thus allowing for an overall faster computation of the
  partition in some cases.

  Returns the partition of S as a list of lists.

  \(FN S &rest G1 ... GN F\)"

    (cond
     ((= (length s) 0) nil)
     ((or (null fns)
          (< (length s) 2))
      (list s))
     (t
      (seq-mapcat
       (lambda (elt)
         (apply #'partition-by (cdr elt) (cdr fns)))
       (seq-group-by (car fns) s)))))

  (partition-by
   (seq-filter #'file-regular-p (directory-files "/tmp" t))
   (lambda (file) (nth 7 (file-attributes file)))
   (lambda (file) (with-temp-buffer
                    (insert-file-contents-literally file)
                    (md5 (current-buffer)))))
#+END_SRC

Andreas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]