utils: Streamline multi-split-at.

This commit is contained in:
Sergiu Ivanov 2020-11-03 23:58:26 +01:00
parent c4a5327b4b
commit ed44d3666c

View file

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