sync
This commit is contained in:
@@ -4,7 +4,7 @@ export type ElementPredicate<T = any> = (index: number, obj: T) => boolean;
|
||||
export type ElementWeight<T = any> = (index: number, obj: T) => number;
|
||||
export type RandomGenerator = () => number;
|
||||
|
||||
export interface RandomOptions<T = any> {
|
||||
export type RandomOptions<T = any> = {
|
||||
predicate?: ElementPredicate<T>;
|
||||
weight?: ElementWeight<T>;
|
||||
random?: RandomGenerator;
|
||||
@@ -13,8 +13,20 @@ export interface RandomOptions<T = any> {
|
||||
export type MaybeAsyncElementPredicate<T = any> = MaybeAsyncFunction<ElementPredicate<T>>;
|
||||
export type MaybeAsyncElementWeight<T = any> = MaybeAsyncFunction<ElementWeight<T>>;
|
||||
|
||||
export interface AsyncRandomOptions<T = any> {
|
||||
export type AsyncRandomOptions<T = any> = {
|
||||
predicate?: MaybeAsyncElementPredicate<T>;
|
||||
weight?: MaybeAsyncElementWeight<T>;
|
||||
random?: RandomGenerator;
|
||||
};
|
||||
|
||||
type RandomElementFound<T> = {
|
||||
found: true;
|
||||
element: T;
|
||||
index: number;
|
||||
};
|
||||
type RandomElementNotFound = {
|
||||
found: false;
|
||||
element: undefined;
|
||||
index: -1;
|
||||
};
|
||||
export type RandomElement<T> = RandomElementFound<T> | RandomElementNotFound;
|
||||
|
||||
Reference in New Issue
Block a user