local Rx = require 'Rx'

local BehaviorSubject = Rx.BehaviorSubject

local unpack = table.unpack or unpack

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

return function(self, initialValueOrSelector, ...)

    local initialValue = { n = select('#', ...), ... }

    if type(initialValueOrSelector) == 'function' then

        return self:multicast(function()
            return BehaviorSubject(unpack(initialValue, 1, initialValue.n))
        end, initialValueOrSelector)

    else

        return self:multicast(function()
            return BehaviorSubject(initialValueOrSelector, unpack(initialValue, 1, initialValue.n))
        end)

    end

end
