File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 11import type { ExecutionContext } from "ava" ;
22import test from "ava" ;
33import {
4+ asyncAllOnce ,
45 asyncAndOnce ,
56 asyncAnyOnce ,
67 asyncAverageOnce ,
@@ -504,3 +505,8 @@ test("asyncAnyOnce", async t => {
504505 t . true ( await asyncAnyOnce ( asyncIterator ( [ 1 , 2 , 3 ] ) , e => e > 2 ) ) ;
505506 t . false ( await asyncAnyOnce ( asyncIterator ( [ 1 , 2 , 3 ] ) , e => e > 4 ) ) ;
506507} ) ;
508+
509+ test ( "asyncAllOnce" , async t => {
510+ t . true ( await asyncAllOnce ( asyncIterator ( [ 1 , 2 , 3 ] ) , e => e < 4 ) ) ;
511+ t . false ( await asyncAllOnce ( asyncIterator ( [ 1 , 2 , 3 ] ) , e => e > 2 ) ) ;
512+ } ) ;
Original file line number Diff line number Diff line change @@ -975,3 +975,21 @@ export function asyncAnyOnceFn<T>(
975975) : ( iterator : AsyncIteratorLike < T > ) => Promise < boolean > {
976976 return async iterator => asyncAnyOnce ( iterator , predicate ) ;
977977}
978+
979+ export async function asyncAllOnce < T > (
980+ iterator : AsyncIteratorLike < T > ,
981+ predicate : ( element : T , index : number ) => boolean | Promise < boolean >
982+ ) : Promise < boolean > {
983+ return (
984+ ( await asyncFindIndexOnce (
985+ iterator ,
986+ async ( element , index ) => ! ( await predicate ( element , index ) )
987+ ) ) == null
988+ ) ;
989+ }
990+
991+ export function asyncAllOnceFn < T > (
992+ predicate : ( element : T , index : number ) => boolean | Promise < boolean >
993+ ) : ( iterator : AsyncIteratorLike < T > ) => Promise < boolean > {
994+ return async iterator => asyncAllOnce ( iterator , predicate ) ;
995+ }
You can’t perform that action at this time.
0 commit comments