Browse Source

Add Observable:compact;

bjorn 10 years ago
parent
commit
cfeabc824b
2 changed files with 17 additions and 0 deletions
  1. 11 0
      doc/README.md
  2. 6 0
      rx.lua

+ 11 - 0
doc/README.md

@@ -12,6 +12,7 @@
   - [subscribe](#subscribeonnext-onerror-oncomplete)
   - [dump](#dumpname)
   - [combineLatest](#combinelatestobservables-combinator)
+  - [compact](#compact)
   - [concat](#concatsources)
   - [distinct](#distinct)
   - [filter](#filterpredicate)
@@ -209,6 +210,16 @@ Returns:
 
 ---
 
+#### `:compact()`
+
+Returns a new Observable that produces the values of the first with falsy values removed.
+
+Returns:
+
+- `Observable`
+
+---
+
 #### `:concat(sources)`
 
 Returns a new Observable that produces the values produced by all the specified Observables in the order they are specified.

+ 6 - 0
rx.lua

@@ -211,6 +211,12 @@ function Observable:combineLatest(...)
   end)
 end
 
+--- Returns a new Observable that produces the values of the first with falsy values removed.
+-- @returns {Observable}
+function Observable:compact()
+  return self:filter(identity)
+end
+
 --- Returns a new Observable that produces the values produced by all the specified Observables in
 -- the order they are specified.
 -- @arg {Observable...} sources - The Observables to concatenate.