Skip to content

Commit

Permalink
Merge pull request #85 from gene-pavlovsky/make-nexttime-condition-op…
Browse files Browse the repository at this point in the history
…tional

Make nextTime's condition optional
  • Loading branch information
back2dos committed Feb 26, 2024
2 parents 58b4bb1 + b92a6d0 commit c3dcbad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/tink/state/Observable.hx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ abstract Observable<T>(ObservableObject<T>) from ObservableObject<T> to Observab
public function combine<A, R>(that:Observable<A>, f:T->A->R):Observable<R>
return Observable.auto(() -> f(value, that.value));

public function nextTime(?options:{ ?butNotNow: Bool, ?hires:Bool }, check:T->Bool):Future<T>
return getNext(options, v -> if (check(v)) Some(v) else None);
public function nextTime(?options:{ ?butNotNow: Bool, ?hires:Bool }, ?condition:T->Bool):Future<T>
return getNext(options,
if (condition == null) Some
else v -> if (condition(v)) Some(v) else None
);

public function getNext<R>(?options:{ ?butNotNow: Bool, ?hires:Bool }, select:T->Option<R>):Future<R> {
var ret = Future.trigger(),
Expand Down Expand Up @@ -360,4 +363,4 @@ class ObservableTools {
static public function flatten<T>(o:Observable<Observable<T>>)
return Observable.auto(() -> Observable.lift(o).value.value);

}
}
3 changes: 2 additions & 1 deletion tests.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-cp src
-cp tests
-D no-deprecation-warnings
-lib tink_unittest
-main RunTests

-lib deep_equal
-lib deep_equal
9 changes: 7 additions & 2 deletions tests/TestBasic.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package;

import tink.state.Scheduler.direct;
import tink.state.*;
import tink.state.Scheduler.direct;

using tink.CoreApi;

Expand Down Expand Up @@ -126,6 +126,11 @@ class TestBasic {

asserts.assert(fired == 4);

await(o.nextTime({ hires: true, }));
set(0);

asserts.assert(fired == 5);

return asserts.done();
}

Expand All @@ -152,7 +157,7 @@ class TestBasic {

return asserts.done();
}

public function mapAsync() {
final s = new State(0);
final o:Observable<Int> = s;
Expand Down

0 comments on commit c3dcbad

Please sign in to comment.