 class SortedExtensions
 
 SortedSeq = (->
-  Tree = new FingerTreeType OrderMeasure, SortedExtensions
-
   class Instance
     constructor: (@data) ->
 

      [l, r] = split @data, x
      new Instance l.concat r.dropUntil (m) -> m > x

    merge = (t1, t2) ->
      if t2.isEmpty()
        t1
      else
        k = t2.first()
        [l, x, r] = t1.split (m) -> m > k
        l.before(k).concat merge(t2.rest(), r.after(x))

    merge: (other) -> new Instance merge this.data, other.data

    toString: -> @data.toString()


  Empty = new Instance Tree.buildLeft()

  { build: -> Sequence.reduce arguments, Empty, (s, a) -> s.insert a }
)()


if typeof(require) != 'undefined'
  require.paths.unshift('#{__dirname}/../lib')
  { Sequence }                = require('sequence')
  { recur, resolve, suspend } = require('functional')
else
  { Sequence, recur, resolve, suspend } = pazy


class FingerTreeType
