
local function plucker(propList, propListLen)

    return function(x)

        local currentProp = x

        if type(x) ~= 'table' then
            error("Rx.Observable:pluck: attempt to get property from a non-table value")
        end

        for i = 1, propListLen do

            if type(currentProp) ~= 'table' then
                return nil
            end

            currentProp = currentProp[propList[i]]

        end

        return currentProp

    end

end

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

return function(self, ... )

    local propList = { ... }
    local propListLen = select('#', ...)

    if propListLen == 0 then
        error("Rx.Observable:pluck: list of properties cannot be empty.")
    end

    return self:map(plucker(propList, propListLen))

end
