Преглед изворни кода

Add Observable.max; Add Observable.min;

bjorn пре 10 година
родитељ
комит
f30ec0a74c
3 измењених фајлова са 32 додато и 0 уклоњено
  1. 20 0
      doc/README.md
  2. 12 0
      rx.lua
  3. 0 0
      tools/update_documentation.lua

+ 20 - 0
doc/README.md

@@ -232,6 +232,26 @@ Returns:
 
 ---
 
+#### `:max()`
+
+Returns a new Observable that produces the maximum value produced by the original.
+
+Returns:
+
+- `Observable`
+
+---
+
+#### `:min()`
+
+Returns a new Observable that produces the minimum value produced by the original.
+
+Returns:
+
+- `Observable`
+
+---
+
 #### `:merge(sources)`
 
 Returns a new Observable that produces the values produced by all the specified Observables in the order they are produced.

+ 12 - 0
rx.lua

@@ -342,6 +342,18 @@ function Observable:map(callback)
   end)
 end
 
+--- Returns a new Observable that produces the maximum value produced by the original.
+-- @returns {Observable}
+function Observable:max()
+  return self:reduce(math.max)
+end
+
+--- Returns a new Observable that produces the minimum value produced by the original.
+-- @returns {Observable}
+function Observable:min()
+  return self:reduce(math.min)
+end
+
 --- Returns a new Observable that produces the values produced by all the specified Observables in
 -- the order they are produced.
 -- @arg {Observable...} sources - One or more Observables to merge.

+ 0 - 0
tools/documentation.lua → tools/update_documentation.lua