aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-07-04 01:58:35 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-07-07 13:10:38 +0200
commite0fe5252b8a2efa5cc1132ecc5baa80873ac4c57 (patch)
tree4a5e6b5d3c842f00d8084f42a800b7b6812ea892
parentFinished renamining attribute to property. (diff)
downloadcalp-e0fe5252b8a2efa5cc1132ecc5baa80873ac4c57.tar.gz
calp-e0fe5252b8a2efa5cc1132ecc5baa80873ac4c57.tar.xz
Add insert-ordered.
-rw-r--r--module/util.scm13
1 files changed, 13 insertions, 0 deletions
diff --git a/module/util.scm b/module/util.scm
index 8cc0e032..00af7258 100644
--- a/module/util.scm
+++ b/module/util.scm
@@ -439,6 +439,19 @@
(cons (car rem) (loop (not flipflop) (cdr rem)))
))))
+;; @example
+;; (insert-ordered 5 (iota 10))
+;; ⇒ (0 1 2 3 4 5 5 6 7 8 9)
+;; @end example
+(define*-public (insert-ordered item collection optional: (< <))
+ (cond [(null? collection)
+ (list item)]
+ [(< item (car collection))
+ (cons item collection)]
+ [else
+ (cons (car collection)
+ (insert-ordered item (cdr collection) <))]))
+
(define-syntax ->