local Rx = require 'Rx'

local AnonymousObservable = Rx.AnonymousObservable

--------------------------------------------------------------------------------

return function(self)

    return AnonymousObservable(function(observer)

        local arr = {}

        return self:subscribe(
            function(x)
                arr[#arr + 1] = x
            end,
            function(...)
                observer:onError(...)
            end,
            function()
                observer:onNext(arr)
                observer:onCompleted()
            end
        )

    end)

end
