Browse Source

Add Observable.partition;

bjorn 10 years ago
parent
commit
66cb0ad598
2 changed files with 25 additions and 0 deletions
  1. 16 0
      doc/README.md
  2. 9 0
      rx.lua

+ 16 - 0
doc/README.md

@@ -29,6 +29,7 @@ RxLua
   - [min](#min)
   - [merge](#mergesources)
   - [pack](#pack)
+  - [partition](#partitionpredicate)
   - [pluck](#pluckkey)
   - [reduce](#reduceaccumulator-seed)
   - [reject](#rejectpredicate)
@@ -380,6 +381,21 @@ Returns:
 
 ---
 
+#### `:partition(predicate)`
+
+Returns two Observables: one that produces values for which the predicate returns truthy for, and another that produces values for which the predicate returns falsy.
+
+Arguments:
+
+- `predicate` (`function`) - The predicate used to partition the values.
+
+Returns:
+
+- `Observable`
+- `Observable`
+
+---
+
 #### `:pluck(key)`
 
 Returns a new Observable that produces values computed by extracting the given key from the tables produced by the original.

+ 9 - 0
rx.lua

@@ -489,6 +489,15 @@ function Observable:pack()
   return self:map(pack)
 end
 
+--- Returns two Observables: one that produces values for which the predicate returns truthy for,
+-- and another that produces values for which the predicate returns falsy.
+-- @arg {function} predicate - The predicate used to partition the values.
+-- @returns {Observable}
+-- @returns {Observable}
+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
 -- tables produced by the original.
 -- @arg {function} key - The key to extract from the table.