AsyncPipe; table schemata; migrations; File logging
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from './Collection'
|
||||
import {Iterable, StopIteration} from './Iterable'
|
||||
import {applyWhere, WhereOperator} from './where'
|
||||
import {AsyncPipe, Pipe} from '../support/Pipe'
|
||||
type AsyncCollectionComparable<T> = CollectionItem<T>[] | Collection<T> | AsyncCollection<T>
|
||||
type AsyncKeyFunction<T, T2> = (item: CollectionItem<T>, index: number) => CollectionItem<T2> | Promise<CollectionItem<T2>>
|
||||
type AsyncCollectionFunction<T, T2> = (items: AsyncCollection<T>) => T2
|
||||
@@ -318,6 +319,24 @@ export class AsyncCollection<T> {
|
||||
return new Collection<T2>(newItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by mapping the items in this collection using the given function,
|
||||
* excluding any for which the function resolves undefined.
|
||||
* @param func
|
||||
*/
|
||||
async partialMap<T2>(func: AsyncKeyFunction<T, T2 | undefined>): Promise<Collection<NonNullable<T2>>> {
|
||||
const newItems: CollectionItem<NonNullable<T2>>[] = []
|
||||
|
||||
await this.each(async (item, index) => {
|
||||
const result = await func(item, index)
|
||||
if ( typeof result !== 'undefined' ) {
|
||||
newItems.push(result as NonNullable<T2>)
|
||||
}
|
||||
})
|
||||
|
||||
return new Collection<NonNullable<T2>>(newItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given operator returns true for every item in the collection.
|
||||
* @param {AsyncKeyFunction} func
|
||||
@@ -783,10 +802,24 @@ export class AsyncCollection<T> {
|
||||
* Return the value of the function, passing this collection to it.
|
||||
* @param {AsyncCollectionFunction} func
|
||||
*/
|
||||
pipe<T2>(func: AsyncCollectionFunction<T, T2>): any {
|
||||
pipeTo<T2>(func: AsyncCollectionFunction<T, T2>): any {
|
||||
return func(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new Pipe of this collection.
|
||||
*/
|
||||
pipe(): Pipe<AsyncCollection<T>> {
|
||||
return Pipe.wrap(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new AsyncPipe of this collection.
|
||||
*/
|
||||
asyncPipe(): AsyncPipe<AsyncCollection<T>> {
|
||||
return AsyncPipe.wrap(this)
|
||||
}
|
||||
|
||||
/* async pop(): Promise<MaybeCollectionItem<T>> {
|
||||
const nextItem = await this.storedItems.next()
|
||||
if ( !nextItem.done ) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {Pipe} from '../support/Pipe'
|
||||
import {AsyncPipe, Pipe} from '../support/Pipe'
|
||||
|
||||
type CollectionItem<T> = T
|
||||
type MaybeCollectionItem<T> = CollectionItem<T> | undefined
|
||||
type KeyFunction<T, T2> = (item: CollectionItem<T>, index: number) => CollectionItem<T2>
|
||||
type KeyReducerFunction<T, T2> = (current: any, item: CollectionItem<T>, index: number) => T2
|
||||
type CollectionFunction<T, T2> = (items: Collection<T>) => T2
|
||||
type KeyOperator<T, T2> = string | KeyFunction<T, T2>
|
||||
type KeyOperator<T, T2> = keyof T | KeyFunction<T, T2>
|
||||
type AssociatedCollectionItem<T2, T> = { key: T2, item: CollectionItem<T> }
|
||||
type CollectionComparable<T> = CollectionItem<T>[] | Collection<T>
|
||||
type DeterminesEquality<T> = (item: CollectionItem<T>, other: any) => boolean
|
||||
@@ -313,6 +313,24 @@ class Collection<T> {
|
||||
return new Collection<T2>(newItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by mapping the items in this collection using the given function,
|
||||
* excluding any for which the function returns undefined.
|
||||
* @param func
|
||||
*/
|
||||
partialMap<T2>(func: KeyFunction<T, T2 | undefined>): Collection<NonNullable<T2>> {
|
||||
const newItems: CollectionItem<NonNullable<T2>>[] = []
|
||||
|
||||
this.each(((item, index) => {
|
||||
const result = func(item, index)
|
||||
if ( typeof result !== 'undefined' ) {
|
||||
newItems.push(result as NonNullable<T2>)
|
||||
}
|
||||
}))
|
||||
|
||||
return new Collection<NonNullable<T2>>(newItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this collection to an object keyed by the given field.
|
||||
*
|
||||
@@ -354,10 +372,10 @@ class Collection<T> {
|
||||
this.allAssociated(key).forEach(assoc => {
|
||||
i += 1
|
||||
|
||||
if ( typeof value === 'string' ) {
|
||||
obj[assoc.key] = (assoc.item as any)[value]
|
||||
} else {
|
||||
if ( typeof value === 'function' ) {
|
||||
obj[assoc.key] = value(assoc.item, i)
|
||||
} else {
|
||||
obj[assoc.key] = (assoc.item[value] as any) as T2
|
||||
}
|
||||
})
|
||||
|
||||
@@ -805,6 +823,13 @@ class Collection<T> {
|
||||
return Pipe.wrap(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new AsyncPipe of this collection.
|
||||
*/
|
||||
asyncPipe(): AsyncPipe<Collection<T>> {
|
||||
return AsyncPipe.wrap(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the last item from this collection.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user