diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 615c200..9e36df7 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -392,6 +392,17 @@ a couple conversions. (lists-transpose '((a b) (1 2 3) (#t))) ]} +@defproc[(append-lists [lsts (Listof (List (Listof a) (Listof a)))]) + (Listof (Listof a))]{ + +@racket[lsts] is a list of rows, in which each row is split in two halves. +The function returns the list of the same rows, with the two halves appended. + +@examples[#:eval utils-evaluator +(append-lists '(((1 2) (a b)) + ((3 4) (c d)))) +]} + @section{Randomness} @defproc*[([(in-random) (Sequenceof Flonum)] diff --git a/utils.rkt b/utils.rkt index d2ce7f7..c47fadc 100644 --- a/utils.rkt +++ b/utils.rkt @@ -13,7 +13,7 @@ list-sets->list-strings pretty-print-set pretty-print-set-sets update-vertices/unweighted update-graph dotit collect-by-key collect-by-key/sets ht-values/list->set hash->list/ordered - multi-split-at lists-transpose in-random cartesian-product-2/stream + multi-split-at lists-transpose append-lists in-random cartesian-product-2/stream cartesian-product/stream boolean-power boolean-power/stream any->01 01->boolean @@ -443,6 +443,18 @@ (test-case "lists-transpose" (check-equal? (lists-transpose '((1 2) (a b))) '((1 a) (2 b))))) +(: append-lists (All (a) (-> (Listof (List (Listof a) (Listof a))) (Listof (Listof a))))) +(define (append-lists lsts) + (for/list ([pr lsts]) + (append (car pr) (cadr pr)))) + +(module+ test + (test-case "append-lists" + (check-equal? (append-lists '(((1 2) (a b)) + ((3 4) (c d)))) + '((1 2 a b) + (3 4 c d))))) + (: in-random (case-> (-> (Sequenceof Flonum)) (-> Integer (Sequenceof Nonnegative-Fixnum))