rebellion icon indicating copy to clipboard operation
rebellion copied to clipboard

Transducer equivalent to split-at

Open jackfirth opened this issue 5 years ago • 2 comments

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)))

jackfirth avatar Nov 13 '19 07:11 jackfirth

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?

jackfirth avatar Nov 13 '19 07:11 jackfirth

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.

jackfirth avatar Nov 13 '19 07:11 jackfirth