Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added list-join fn

  • Loading branch information...
commit 509de3d7550be6d9a0d82897f8ac346adf371bf9 1 parent 72ff364
Rob Hunter authored December 17, 2008

Showing 1 changed file with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. 18  util.scm
18  util.scm
@@ -94,6 +94,7 @@
94 94
          alist-cons
95 95
          alist-merge
96 96
          receive
  97
+         list-join
97 98
          
98 99
          aif
99 100
          awhen
@@ -429,6 +430,23 @@
429 430
   (delete-duplicates! (concatenate (reverse alists))
430 431
                       (lambda (pair1 pair2) (eq? (car pair1) (car pair2)))))
431 432
 
  433
+;;
  434
+;; list-join
  435
+;;
  436
+;; (-> (listof any?) any? (listof any?))
  437
+;;
  438
+;; Analagous to string-join.
  439
+;; E.g., (list-join '(a b c) "hi!") => (a "hi" b "hi" c)
  440
+;;
  441
+(define (list-join lst joiner)
  442
+  (concatenate (pair-fold-right (lambda (pair acc)
  443
+                                  (let ((elt (car pair)))
  444
+                                    (cons (if (empty? (cdr pair))
  445
+                                              (list elt)
  446
+                                              (list elt joiner))
  447
+                                          acc)))
  448
+                                '() lst)))
  449
+
432 450
 (define (alist-key-filter fn alist)
433 451
   (filter (match-lambda ((list-rest k v) (fn k))) alist))
434 452
 

0 notes on commit 509de3d

Please sign in to comment.
Something went wrong with that request. Please try again.