diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-04 01:58:35 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-07 13:10:38 +0200 |
commit | e0fe5252b8a2efa5cc1132ecc5baa80873ac4c57 (patch) | |
tree | 4a5e6b5d3c842f00d8084f42a800b7b6812ea892 | |
parent | Finished renamining attribute to property. (diff) | |
download | calp-e0fe5252b8a2efa5cc1132ecc5baa80873ac4c57.tar.gz calp-e0fe5252b8a2efa5cc1132ecc5baa80873ac4c57.tar.xz |
Add insert-ordered.
Diffstat (limited to '')
-rw-r--r-- | module/util.scm | 13 |
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 -> |