Type alias Result<A, E>

Result<A, E>: Result.Ok<A> | Result.Err<E>

The result of a computation can either be Ok or Err

Remark

If you are familiar with functional programming you will recognize this as you standard Either type. I've kept the implementation very basic. If you want a richer type with a bnuch of utility functions you can easily wrap the run function yourself.

import * as Results from "ts-results";
import * as P from "@honungsburk/kombo/Simple";

const run =
<A>(parser: Parser<A>) =>
(src: string): Results.Result<A, DeadEnd[]> => {
const res = P.run(parser)(src);
if(P.isErr(res)){
return new Results.Err(res.value)
} else {
return new Results.Ok(res.value)
}
};

See

Type Parameters

  • A

  • E