Browse Source

Alphabetization;

bjorn 9 years ago
parent
commit
ef257033cd
2 changed files with 42 additions and 42 deletions
  1. 11 11
      doc/README.md
  2. 31 31
      src/observable.lua

+ 11 - 11
doc/README.md

@@ -17,11 +17,11 @@ RxLua
   - [fromTable](#fromtabletable-iterator-keys)
   - [fromCoroutine](#fromcoroutinecoroutine)
   - [dump](#dumpname-formatter)
-  - [distinctUntilChanged](#distinctuntilchangedcomparator)
   - [combineLatest](#combinelatestobservables-combinator)
   - [compact](#compact)
   - [concat](#concatsources)
   - [distinct](#distinct)
+  - [distinctUntilChanged](#distinctuntilchangedcomparator)
   - [filter](#filterpredicate)
   - [find](#findpredicate)
   - [first](#first)
@@ -213,16 +213,6 @@ Subscribes to this Observable and prints values it produces.
 
 ---
 
-#### `:distinctUntilChanged(comparator)`
-
-Returns an Observable that only produces values from the original if they are different from the previous value.
-
-| Name | Type | Default | Description |
-|------|------|---------|-------------|
-| `comparator` | function |  | A function used to compare 2 values. If unspecified, == is used. |
-
----
-
 #### `:combineLatest(observables, combinator)`
 
 Returns a new Observable that runs a combinator function on the most recent values from a set of Observables whenever any of them produce a new value. The results of the combinator function are produced by the new Observable.
@@ -256,6 +246,16 @@ Returns a new Observable that produces the values from the original with duplica
 
 ---
 
+#### `:distinctUntilChanged(comparator)`
+
+Returns an Observable that only produces values from the original if they are different from the previous value.
+
+| Name | Type | Default | Description |
+|------|------|---------|-------------|
+| `comparator` | function |  | A function used to compare 2 values. If unspecified, == is used. |
+
+---
+
 #### `:filter(predicate)`
 
 Returns a new Observable that only produces values of the first that satisfy a predicate.

+ 31 - 31
src/observable.lua

@@ -117,37 +117,6 @@ function Observable:dump(name, formatter)
   return self:subscribe(onNext, onError, onComplete)
 end
 
---- Returns an Observable that only produces values from the original if they are different from
--- the previous value.
--- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
--- @returns {Observable}
-function Observable:distinctUntilChanged(comparator)
-  comparator = comparator or util.eq
-
-  return Observable.create(function(observer)
-    local first = true
-    local currentValue = nil
-
-    local function onNext(value, ...)
-      if first or not comparator(value, currentValue) then
-        observer:onNext(value, ...)
-        currentValue = value
-        first = false
-      end
-    end
-
-    local function onError(message)
-      return observer:onError(onError)
-    end
-
-    local function onComplete()
-      return observer:onComplete()
-    end
-
-    return self:subscribe(onNext, onError, onComplete)
-  end)
-end
-
 --- Returns a new Observable that runs a combinator function on the most recent values from a set
 -- of Observables whenever any of them produce a new value. The results of the combinator function
 -- are produced by the new Observable.
@@ -262,6 +231,37 @@ function Observable:distinct()
   end)
 end
 
+--- Returns an Observable that only produces values from the original if they are different from
+-- the previous value.
+-- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
+-- @returns {Observable}
+function Observable:distinctUntilChanged(comparator)
+  comparator = comparator or util.eq
+
+  return Observable.create(function(observer)
+    local first = true
+    local currentValue = nil
+
+    local function onNext(value, ...)
+      if first or not comparator(value, currentValue) then
+        observer:onNext(value, ...)
+        currentValue = value
+        first = false
+      end
+    end
+
+    local function onError(message)
+      return observer:onError(onError)
+    end
+
+    local function onComplete()
+      return observer:onComplete()
+    end
+
+    return self:subscribe(onNext, onError, onComplete)
+  end)
+end
+
 --- Returns a new Observable that only produces values of the first that satisfy a predicate.
 -- @arg {function} predicate - The predicate used to filter values.
 -- @returns {Observable}