Make new routing system the default
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-01-19 13:24:59 -06:00
parent 8cf19792a6
commit dc16dfdb81
17 changed files with 298 additions and 535 deletions

View File

@@ -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.