def drain_take_go
import bend-collections@1.0.0.0/src/containers/binary_heap.bend as BinaryHeapimport Base
345# Take the root out of a copy holding `n` elements. Emptiness is decided by
346# the count, not by reading slot 0: the drain must stop at `n = 0` whatever
347# the slots above the heap hold (and it saves one array read per element).
348def drain_take_go(~A: Data, +n: U32, arr: Array<Maybe<&2, A>>, empty: Bool) -> Drain<A>:
349 match empty:
350 case True{}:
351 DrDone{arr}
352 case False{}:
353 drain_take(~A, U32.sub(n, 1), Array.get(Maybe<&2, A>, arr, 0))