ts-results
Advanced tools
Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2
{ | ||
"name": "ts-results", | ||
"version": "2.0.0-alpha.1", | ||
"version": "2.0.0-alpha.2", | ||
"description": "A typescript implementation of Rust's Result object.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import { ObservableInput, OperatorFunction } from 'rxjs'; | ||
import { Result, ResultErrType, ResultOkType } from './index'; | ||
export declare function resultMap<R extends Result<any, any>, T>(mapper: (val: ResultOkType<R>) => T): OperatorFunction<R, Result<T, ResultErrType<R>>>; | ||
export declare function resultMap<R extends Result<any, any>, T2>(mapper: null | undefined, errMapper: (val: ResultErrType<R>) => T2): OperatorFunction<R, Result<ResultOkType<R>, T2>>; | ||
export declare function resultMap<R extends Result<any, any>, T, T2>(mapper: (val: ResultOkType<R>) => T, errMapper: (val: ResultErrType<R>) => T2): OperatorFunction<R, Result<T, T2>>; | ||
export declare function resultMapErr<R extends Result<any, any>, E>(mapper: (val: ResultErrType<R>) => E): OperatorFunction<R, Result<ResultOkType<R>, E>>; | ||
export declare function resultMapTo<R extends Result<any, any>, T>(value: T): OperatorFunction<R, Result<T, ResultErrType<R>>>; | ||
export declare function resultMapErrTo<R extends Result<any, any>, T>(value: T): OperatorFunction<R, Result<ResultOkType<R>, T>>; | ||
export declare function elseMap<R extends Result<any, any>, T>(mapper: (val: ResultErrType<R>) => T): OperatorFunction<R, ResultOkType<R> | T>; | ||
@@ -13,1 +13,3 @@ export declare function elseMapTo<R extends Result<any, any>, T>(value: T): OperatorFunction<R, ResultOkType<R> | T>; | ||
export declare function resultMergeMap<R extends Result<any, any>, T>(mapper: (val: ResultOkType<R>) => ObservableInput<T>): OperatorFunction<R, Result<T, ResultErrType<R>>>; | ||
export declare function filterResultOk<R extends Result<any, any>>(): OperatorFunction<R, ResultOkType<R>>; | ||
export declare function filterResultErr<R extends Result<any, any>>(): OperatorFunction<R, ResultErrType<R>>; |
import { of } from 'rxjs'; | ||
import { map, mergeMap, switchMap } from 'rxjs/operators'; | ||
import { filter, map, mergeMap, switchMap } from 'rxjs/operators'; | ||
import { Err, Ok } from './index'; | ||
export function resultMap(mapper, errMapper) { | ||
export function resultMap(mapper) { | ||
return (source) => { | ||
return source.pipe(map(result => { | ||
if (result.ok) { | ||
if (mapper) { | ||
const newVal = mapper(result.val); | ||
return new Ok(newVal); | ||
} | ||
else { | ||
return result; | ||
} | ||
} | ||
else { | ||
if (errMapper) { | ||
return new Err(errMapper(result.val)); | ||
} | ||
else { | ||
return result; | ||
} | ||
} | ||
})); | ||
return source.pipe(map(result => result.map(mapper))); | ||
}; | ||
} | ||
export function resultMapErr(mapper) { | ||
return (source) => { | ||
return source.pipe(map(result => result.mapErr(mapper))); | ||
}; | ||
} | ||
export function resultMapTo(value) { | ||
return (source) => { | ||
return source.pipe(map(result => { | ||
if (result.ok) { | ||
return new Ok(value); | ||
} | ||
else { | ||
return result; | ||
} | ||
})); | ||
return source.pipe(map(result => result.map(() => value))); | ||
}; | ||
} | ||
export function resultMapErrTo(value) { | ||
return (source) => { | ||
return source.pipe(map(result => result.mapErr(() => value))); | ||
}; | ||
} | ||
export function elseMap(mapper) { | ||
@@ -101,2 +86,12 @@ return (source) => { | ||
} | ||
export function filterResultOk() { | ||
return (source) => { | ||
return source.pipe(filter(result => result.ok), map(result => result.val)); | ||
}; | ||
} | ||
export function filterResultErr() { | ||
return (source) => { | ||
return source.pipe(filter(result => result.err), map(result => result.val)); | ||
}; | ||
} | ||
//# sourceMappingURL=rxjs-operators.js.map |
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
20520
213