halves ( seq -- first-slice second-slice )


Vocabulary
sequences

Inputs
seqa sequence


Outputs
first-slicea slice
second-slicea slice


Word description
Splits a sequence into two slices at the midpoint. If the sequence has an odd number of elements, the extra element is returned in the second slice.

Examples
USING: arrays sequences prettyprint kernel ; { 1 2 3 4 5 } halves [ >array . ] bi@
{ 1 2 } { 3 4 5 }


Definition


: halves ( seq -- first-slice second-slice )
dup midpoint@ cut-slice ; inline