utils: Streamline multi-split-at.
This commit is contained in:
parent
c4a5327b4b
commit
ed44d3666c
1 changed files with 6 additions and 6 deletions
12
utils.rkt
12
utils.rkt
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue