++- Array sort a.k.a. "moving sort" 

sort = a order-by + sorted ->
  s = 1 ..
  bitmap : array : integer : 2^1 : [a] = {} ..

  do ->
    index = take-next a bitmap order-by

    if index ->
      bitmap.index = 1
      sorted.s = a.index; s ++

      iterate
    else
      leave
    ;
  ;
_
  a : array : <T>
  order-by : SORT_* : {ASC DESC}
  sorted : array : T : [a]
;

take-next sort = a bitmap order-by + index ->
  latest-found = a.1 ..; index = 0 ..

  do {1..a._} i ->
    if !bitmap.i ->   
      if (order-by = SORT_ASC) ->
        if (latest-found < a.i) -> 
          latest-found = a.i; index = i
        else
          <>
        ;
      else
        if (latest-found > a.i) -> 
          latest-found = a.i; index = i
        else
          <>
        ;
      ;
    else
      <>
    ;
  ;
;

sort :: _ SORT_ASC

