Commit 3b765a50 authored by Jens Nevens's avatar Jens Nevens

git subrepo pull (merge) systems/utils

subrepo:
  subdir:   "systems/utils"
  merged:   "0b69ea3"
upstream:
  origin:   "gitlab@gitlab.ai.vub.ac.be:ehai/utils.git"
  branch:   "master"
  commit:   "15d4224"
git-subrepo:
  version:  "0.4.0"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "5d6aba9"
parent 2cc3be64
......@@ -6,7 +6,7 @@
[subrepo]
remote = gitlab@gitlab.ai.vub.ac.be:ehai/utils.git
branch = master
commit = 09d2352ff278b599f28bd59b2e3512d283a27aa1
commit = 15d4224cf3a8c7597ccd7f07e170c4ed50b186c5
parent = 970fd717771177df6fd351041d3b12974fd1942c
cmdver = 0.4.0
method = merge
......@@ -270,7 +270,8 @@ nil."
collect-ignore-nils
remove-first
remove-nth
cartesian-product))
cartesian-product
group-by))
(defun insert-after (lst index newelt)
"Insert an elt into a list after a certain position."
......@@ -536,6 +537,25 @@ element for which the sought value satisfies the test"
;; (sublist-position '(c d) '(a b c d))
;; ==> 2
(defun group-by (sequence fn &key (test #'eql))
"applies fn to each elem of sequence. the elems for which fn
yields the same value are grouped together. use :test to
compare the results of applying fn to each elem."
(loop with result = nil
for elem in sequence
for key = (funcall fn elem)
if (assoc key result :test test)
do (push elem (cdr (assoc key result :test test)))
else
do (push (cons key (list elem)) result)
finally
(return result)))
;; (group-by '((3) (1 2) (1) (1 3) (2) (1 2 3) (2 3)) #'length :test #'=)
;; ==> ((3 (1 2 3))
;; (2 (2 3) (1 3) (1 2))
;; (1 (2) (1) (3)))
;; ############################################################################
;; list randomize utilities:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment