-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add
anyOf
operator (#2516)
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
cold, | ||
hot, | ||
} from 'jasmine-marbles'; | ||
|
||
import { anyOf } from './any-of.pipe'; | ||
|
||
describe('@daffodil/core | anyOf', () => { | ||
it('should return true when any of the input streams emit a truthy value', () => { | ||
expect(anyOf([ | ||
hot('ab', { a: true, b: true }), | ||
hot('ab', { a: false, b: true }), | ||
])).toBeObservable(cold('a(bc)', { a: true, b: true, c: true })); | ||
}); | ||
|
||
it('should return false when all of the input streams emit a falsy value', () => { | ||
expect(anyOf([ | ||
hot('ab', { a: true, b: false }), | ||
hot('ab', { a: false, b: false }), | ||
])).toBeObservable(cold('a(bc)', { a: true, b: false, c: false })); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
Observable, | ||
combineLatest, | ||
map, | ||
} from 'rxjs'; | ||
|
||
/** | ||
* Accepts a list of input observables and emits true when any of the inputs emit a truthy value. | ||
* Does not emit until all of the input streams have emitted at least once. | ||
*/ | ||
export const anyOf = (items: Observable<boolean>[]) => combineLatest(items).pipe(map((els) => els.reduce( | ||
(agg, el) => agg || el, false)), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './backoff.pipe'; | ||
export * from './any-of.pipe'; | ||
export * from './all-of.pipe'; |