@async-generators/last
Advanced tools
Comparing version 0.1.1 to 0.1.2
export default function <T>(source: AsyncIterable<T> | Iterable<T>): Promise<T | undefined>; | ||
export default function <T>(source: AsyncIterable<T> | Iterable<T>, predicate: (item: T) => boolean): Promise<T | undefined>; | ||
export default function <T>(source: AsyncIterable<T> | Iterable<T>, predicate: (item: T) => Promise<boolean> | boolean): Promise<T | undefined>; |
@@ -5,12 +5,16 @@ "use strict"; | ||
async function basic(source) { | ||
let last = undefined; | ||
for await (let item of iterable_1.default(source)) { | ||
return item; | ||
last = item; | ||
} | ||
return last; | ||
} | ||
async function predicated(source, predicate) { | ||
let last = undefined; | ||
for await (let item of iterable_1.default(source)) { | ||
if (predicate(item)) { | ||
return item; | ||
if (await predicate(item)) { | ||
last = item; | ||
} | ||
} | ||
return last; | ||
} | ||
@@ -17,0 +21,0 @@ function default_1(source, predicate) { |
export default function <T>(source: AsyncIterable<T> | Iterable<T>): Promise<T | undefined>; | ||
export default function <T>(source: AsyncIterable<T> | Iterable<T>, predicate: (item: T) => boolean): Promise<T | undefined>; | ||
export default function <T>(source: AsyncIterable<T> | Iterable<T>, predicate: (item: T) => Promise<boolean> | boolean): Promise<T | undefined>; |
import iterable from '@async-generators/iterable'; | ||
async function basic(source) { | ||
let last = undefined; | ||
for await (let item of iterable(source)) { | ||
return item; | ||
last = item; | ||
} | ||
return last; | ||
} | ||
async function predicated(source, predicate) { | ||
let last = undefined; | ||
for await (let item of iterable(source)) { | ||
if (predicate(item)) { | ||
return item; | ||
if (await predicate(item)) { | ||
last = item; | ||
} | ||
} | ||
return last; | ||
} | ||
@@ -14,0 +18,0 @@ export default function (source, predicate) { |
{ | ||
"name": "@async-generators/last", | ||
"description": "get the last (predicated) item from a source iterable", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Meirion Hughes", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
9912
88