Add append-lists.

This commit is contained in:
Sergiu Ivanov 2022-03-06 20:52:33 +01:00
parent 66f1157200
commit 929bf09299
2 changed files with 24 additions and 1 deletions

View File

@ -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)]

View File

@ -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))