Comparing version 0.1.1 to 0.1.2
146
index.ts
export interface Option<T> { | ||
map <U>(fn: (a: T) => U): Option<U>; | ||
/** | ||
* Returns true if the option is a Some value | ||
*/ | ||
isSome(): boolean; | ||
/** | ||
* Returns true if the option is a None value | ||
*/ | ||
isNone(): boolean; | ||
/** | ||
* Returns check result if the option is a Some value | ||
*/ | ||
isSomeAnd(fn: (a: T) => boolean): boolean; | ||
/** | ||
* Returns check result if the option is a None value | ||
*/ | ||
isNoneAnd(fn: () => boolean): boolean; | ||
/** | ||
* Returns the inner T of a Some(T). Throws an exception if the self value equals None. | ||
*/ | ||
unwrap(): T; | ||
/** | ||
* Returns the contained value or a default. | ||
* @param def | ||
*/ | ||
unwrapOr(def: T): T; | ||
/** | ||
* Returns the contained value or computes it from a closure. | ||
* @param f | ||
*/ | ||
unwrapOrElse(f: () => T): T; | ||
/** | ||
* Maps an Option<T> to Option<U> by applying a function to a contained value | ||
* @param f | ||
*/ | ||
map<U>(f: (a: T) => U): Option<U>; | ||
/** | ||
* Applies a function to the contained value or returns a default. | ||
* @param def | ||
* @param f | ||
*/ | ||
mapOr<U>(def: U, f: (a: T) => U): U; | ||
/** | ||
* Applies a function to the contained value or computes a default. | ||
* @param def | ||
* @param f | ||
*/ | ||
mapOrElse<U>(def: () => U, f: (a: T) => U): U; | ||
/** | ||
* Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err). | ||
* @param err | ||
*/ | ||
okOr<E>(err: E): Result<T, E>; | ||
/** | ||
* Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err()). | ||
* @param err | ||
*/ | ||
okOrElse<E>(err: () => E): Result<T, E>; | ||
/** | ||
* Returns None if the option is None, otherwise returns optb. | ||
* @param optb | ||
*/ | ||
and<U>(optb: Option<U>): Option<U>; | ||
/** | ||
* Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. | ||
* Some languages call this operation flatmap. | ||
* @param f | ||
*/ | ||
andThen<U>(f: (a: T) => Option<U>): Option<U>; | ||
/** | ||
* Returns the option if it contains a value, otherwise returns optb. | ||
* @param optb | ||
*/ | ||
or(optb: Option<T>): Option<T>; | ||
/** | ||
* Returns the option if it contains a value, otherwise calls f and returns the result. | ||
* @param f | ||
*/ | ||
orElse(f: () => Option<T>): Option<T>; | ||
@@ -189,14 +265,78 @@ } | ||
export interface Result<T, E> { | ||
map<U>(fn: (a: T) => U): Result<U, E>; | ||
mapErr<U>(fn: (a: E) => U): Result<T, U>; | ||
/** | ||
* Returns true if the result is Ok | ||
*/ | ||
isOk(): boolean; | ||
/** | ||
* Returns true if the result is Err | ||
*/ | ||
isErr(): boolean; | ||
/** | ||
* Convert from Result<T, E> to Option<T> | ||
* Converts self into an Option<T>, and discarding the error, if any. | ||
*/ | ||
ok(): Option<T>; | ||
/** | ||
* Convert from Result<T, E> to Option<E> | ||
* Converts self into an Option<E>, and discarding the value, if any. | ||
*/ | ||
err(): Option<E>; | ||
/** | ||
* Maps a Result<T, E> to Result<U, E> by applying a function to an contained Ok value, leaving an Err value untouched. | ||
* This function can be used to compose the results of two functions. | ||
* @param fn | ||
*/ | ||
map<U>(fn: (a: T) => U): Result<U, E>; | ||
/** | ||
* Maps a Result<T, E> to Result<T, F> by applying a function to an contained Err value, leaving an Ok value untouched. | ||
* This function can be used to pass through a successful result while handling an error. | ||
* @param fn | ||
*/ | ||
mapErr<U>(fn: (a: E) => U): Result<T, U>; | ||
/** | ||
* Returns res if the result is Ok, otherwise returns the Err value of self. | ||
* @param res | ||
*/ | ||
and<U>(res: Result<U,E>): Result<U,E>; | ||
/** | ||
* Calls op if the result is Ok, otherwise returns the Err value of self. | ||
* This function can be used for control flow based on result values. | ||
* @param op | ||
*/ | ||
andThen<U>(op: (a: T) => Result<U,E>): Result<U,E>; | ||
/** | ||
* Returns res if the result is Err, otherwise returns the Ok value of self. | ||
* @param res | ||
*/ | ||
or(res: Result<T,E>): Result<T,E>; | ||
/** | ||
* Calls op if the result is Err, otherwise returns the Ok value of self. | ||
* This function can be used for control flow based on result values. | ||
* @param op | ||
*/ | ||
orElse<U>(op: (a: E) => Result<T,U>): Result<T,U>; | ||
/** | ||
* Unwraps a result, yielding the content of an Ok. | ||
*/ | ||
unwrap(): T; | ||
/** | ||
* Unwraps a result, yielding the content of an Ok. Else it returns optb. | ||
*/ | ||
unwrapOr(optb: T): T; | ||
/** | ||
* Unwraps a result, yielding the content of an Err. | ||
* @param op | ||
*/ | ||
unwrapOrElse(op: (u: E) => T): T | ||
@@ -203,0 +343,0 @@ } |
{ | ||
"name": "opty", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Option and Result type ported from Rust", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
49939
18
725
1
210