 Bacon.End = End
 
 nop = ->
+latter = (_, x) -> x
 initial = (value) -> new Initial(value)
 next = (value) -> new Next(value)
 end = -> new End()

  constructor: ->
  isEnd: -> true
  fmap: -> this

class Observable
  onValue: (f) -> @subscribe (event) ->

      unsubBoth

  toProperty: (initValue) ->
   @scan(initValue, latter)

  scan: (seed, f) -> 
    acc = seed
    handleEvent = (event) -> 
      acc = f(acc, event.value) unless event.isEnd()
      @push event.apply(acc)
    d = new Dispatcher(@subscribe, handleEvent)
    subscribe = (sink) ->
      sink initial(acc) if acc?
      d.subscribe(sink)
    new Property(subscribe)

  withHandler: (handler) ->
    new Dispatcher(@subscribe, handler).toEventStream()
