@hyperjump/pact
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -72,2 +72,14 @@ export const map: ( | ||
export const dropWhile: ( | ||
<A>(fn: Predicate<A>, iterator: Iterable<A>) => Generator<A> | ||
) & ( | ||
<A>(fn: Predicate<A>) => (iterator: Iterable<A>) => Generator<A> | ||
); | ||
export const asyncDropWhile: ( | ||
<A>(fn: AsyncPredicate<A>, iterator: AsyncIterable<A>) => AsyncGenerator<A> | ||
) & ( | ||
<A>(fn: AsyncPredicate<A>) => (iterator: AsyncIterable<A>) => AsyncGenerator<A> | ||
); | ||
export const take: ( | ||
@@ -85,2 +97,14 @@ <A>(count: number, iterator: Iterable<A>) => Generator<A> | ||
export const takeWhile: ( | ||
<A>(fn: Predicate<A>, iterator: Iterable<A>) => Generator<A> | ||
) & ( | ||
<A>(fn: Predicate<A>) => (iterator: Iterable<A>) => Generator<A> | ||
); | ||
export const asyncTakeWhile: ( | ||
<A>(fn: AsyncPredicate<A>, iterator: AsyncIterable<A>) => AsyncGenerator<A> | ||
) & ( | ||
<A>(fn: AsyncPredicate<A>) => (iterator: AsyncIterable<A>) => AsyncGenerator<A> | ||
); | ||
export const head: <A>(iterator: Iterable<A>) => A | undefined; | ||
@@ -138,2 +162,14 @@ export const asyncHead: <A>(iterator: AsyncIterable<A>) => Promise<A | undefined>; | ||
export const find: ( | ||
<A>(fn: Predicate<A>, iterator: Iterable<A>) => A | ||
) & ( | ||
<A>(fn: Predicate<A>) => (iterator: Iterable<A>) => A | ||
); | ||
export const asyncFind: ( | ||
<A>(fn: AsyncPredicate<A>, iterator: Iterable<A> | AsyncIterable<A>) => Promise<A> | ||
) & ( | ||
<A>(fn: AsyncPredicate<A>) => (iterator: Iterable<A> | AsyncIterable<A>) => Promise<A> | ||
); | ||
export const count: <A>(iterator: Iterable<A>) => number; | ||
@@ -140,0 +176,0 @@ export const asyncCount: <A>(iterator: AsyncIterable<A>) => Promise<number>; |
@@ -98,2 +98,32 @@ import curry from "just-curry-it"; | ||
export const dropWhile = curry(function* (fn, iter) { | ||
let dropping = true; | ||
for (const n of iter) { | ||
if (dropping) { | ||
if (fn(n)) { | ||
continue; | ||
} else { | ||
dropping = false; | ||
} | ||
} | ||
yield n; | ||
} | ||
}); | ||
export const asyncDropWhile = curry(async function* (fn, iter) { | ||
let dropping = true; | ||
for await (const n of iter) { | ||
if (dropping) { | ||
if (await fn(n)) { | ||
continue; | ||
} else { | ||
dropping = false; | ||
} | ||
} | ||
yield n; | ||
} | ||
}); | ||
export const take = curry(function* (count, iter) { | ||
@@ -117,2 +147,22 @@ const iterator = getIterator(iter); | ||
export const takeWhile = curry(function* (fn, iter) { | ||
for (const n of iter) { | ||
if (fn(n)) { | ||
yield n; | ||
} else { | ||
break; | ||
} | ||
} | ||
}); | ||
export const asyncTakeWhile = curry(async function* (fn, iter) { | ||
for await (const n of iter) { | ||
if (await fn(n)) { | ||
yield n; | ||
} else { | ||
break; | ||
} | ||
} | ||
}); | ||
export const head = (iter) => { | ||
@@ -222,2 +272,18 @@ const iterator = getIterator(iter); | ||
export const find = curry((fn, iter) => { | ||
for (const item of iter) { | ||
if (fn(item)) { | ||
return item; | ||
} | ||
} | ||
}); | ||
export const asyncFind = curry(async (fn, iter) => { | ||
for await (const item of iter) { | ||
if (await fn(item)) { | ||
return item; | ||
} | ||
} | ||
}); | ||
export const count = (iter) => reduce((count) => count + 1, 0, iter); | ||
@@ -224,0 +290,0 @@ export const asyncCount = (iter) => asyncReduce((count) => count + 1, 0, iter); |
{ | ||
"name": "@hyperjump/pact", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Higher order functions for iterators and async iterators", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25038
506