From ed44d3666cafea549668acf5db430fa059031f63 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 3 Nov 2020 23:58:26 +0100 Subject: [PATCH] utils: Streamline multi-split-at. --- utils.rkt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils.rkt b/utils.rkt index 3fa859c..bff50dc 100644 --- a/utils.rkt +++ b/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"