rebellion
rebellion copied to clipboard
Transducer equivalent to split-at
Signature:
(splitting-at [pos position?] [before transducer?] [after transducer?]) -> transducer?
Example:
> (transduce (in-range 0 100)
(splitting-at 50 (taking 5) (taking 3))
#:into into-list)
(list 0 1 2 3 4 50 51 52)
Hypothetical implementation:
(define (splitting-at position before-transducer after-transducer)
(define (before? e) (< (enumerated-position e) position))
(transducer-pipe enumerating
(tagging-by-predicate #:before before? #:after (negate before?))
(forking #:before before-transducer #:after after-transducer)
(mapping variant-value)))
API needs more thought. Two outstanding questions:
- How does this fit in with #328 and related functionality, like
splitf-at
? - How should out-of-bounds indices be handled? Something like #346?
The implementation of the current design is ostensibly not blocked on #347 and #191, but practically speaking they make it much simpler than it would be otherwise.