Make new routing system the default
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:
@@ -14,6 +14,7 @@ type MaybeCollectionIndex = CollectionIndex | undefined
|
||||
type ComparisonFunction<T> = (item: CollectionItem<T>, otherItem: CollectionItem<T>) => number
|
||||
|
||||
import { WhereOperator, applyWhere, whereMatch } from './where'
|
||||
import {Awaitable, Either, isLeft, right, unright} from '../support/types'
|
||||
|
||||
const collect = <T>(items: CollectionItem<T>[]): Collection<T> => Collection.collect(items)
|
||||
const toString = (item: unknown): string => String(item)
|
||||
@@ -316,6 +317,44 @@ class Collection<T> {
|
||||
return new Collection<T2>(newItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by mapping the items in this collection using the given function
|
||||
* where the function returns an Either. The collection is all Right instances. If a Left
|
||||
* is encountered, that value is returned.
|
||||
* @param func
|
||||
*/
|
||||
mapRight<TLeft, TRight>(func: KeyFunction<T, Either<TLeft, TRight>>): Either<TLeft, Collection<TRight>> {
|
||||
const newItems: CollectionItem<TRight>[] = []
|
||||
for ( let i = 0; i < this.length; i += 1 ) {
|
||||
const result = func(this.storedItems[i], i)
|
||||
if ( isLeft(result) ) {
|
||||
return result
|
||||
}
|
||||
|
||||
newItems.push(unright(result))
|
||||
}
|
||||
return right(new Collection<TRight>(newItems))
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by mapping the items in this collection using the given function
|
||||
* where the function returns an Either. The collection is all Right instances. If a Left
|
||||
* is encountered, that value is returned.
|
||||
* @param func
|
||||
*/
|
||||
async asyncMapRight<TLeft, TRight>(func: KeyFunction<T, Awaitable<Either<TLeft, TRight>>>): Promise<Either<TLeft, Collection<TRight>>> {
|
||||
const newItems: CollectionItem<TRight>[] = []
|
||||
for ( let i = 0; i < this.length; i += 1 ) {
|
||||
const result = await func(this.storedItems[i], i)
|
||||
if ( isLeft(result) ) {
|
||||
return result
|
||||
}
|
||||
|
||||
newItems.push(unright(result))
|
||||
}
|
||||
return right(new Collection<TRight>(newItems))
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by mapping the items in this collection using the given function,
|
||||
* excluding any for which the function returns undefined.
|
||||
|
||||
Reference in New Issue
Block a user