Browse Source

Observable.pluck supports nested keys;

bjorn 10 years ago
parent
commit
6471230716
1 changed files with 7 additions and 4 deletions
  1. 7 4
      rx.lua

+ 7 - 4
rx.lua

@@ -506,11 +506,14 @@ function Observable:partition(predicate)
   return self:filter(predicate), self:reject(predicate)
 end
 
---- Returns a new Observable that produces values computed by extracting the given key from the
+--- Returns a new Observable that produces values computed by extracting the given keys from the
 -- tables produced by the original.
--- @arg {function} key - The key to extract from the table.
+-- @arg {string...} keys - The key to extract from the table. Multiple keys can be specified to
+--                         recursively pluck values from nested tables.
 -- @returns {Observable}
-function Observable:pluck(key)
+function Observable:pluck(key, ...)
+  if not key then return self end
+
   return Observable.create(function(observer)
     local function onNext(t)
       return observer:onNext(t[key])
@@ -525,7 +528,7 @@ function Observable:pluck(key)
     end
 
     return self:subscribe(onNext, onError, onComplete)
-  end)
+  end):pluck(...)
 end
 
 --- Returns a new Observable that produces a single value computed by accumulating the results of