utils: Streamline multi-split-at.

This commit is contained in:
Sergiu Ivanov 2020-11-03 23:58:26 +01:00
parent c4a5327b4b
commit ed44d3666c
1 changed files with 6 additions and 6 deletions

View File

@ -563,12 +563,12 @@
;;; position, and then returns two lists: one consisting of the first ;;; position, and then returns two lists: one consisting of the first
;;; halves, and the one consisting of the second halves. ;;; halves, and the one consisting of the second halves.
(define (multi-split-at lsts pos) (define (multi-split-at lsts pos)
(define (split-1 lst res) (for/fold ([lefts '()]
(define-values (l r) (split-at lst pos)) [rights '()]
(match res [(cons left right) #:result (values (reverse lefts) (reverse rights)))
(cons (cons l left) (cons r right))])) ([lst (in-list lsts)])
(match (foldr split-1 (cons '() '()) lsts) (define-values (left right) (split-at lst pos))
[(cons lefts rights) (values lefts rights)])) (values (cons left lefts) (cons right rights))))
(module+ test (module+ test
(test-case "multi-split-at" (test-case "multi-split-at"