From e01cb693bc5737792e2b37abfd98d2d8f81bac4d Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 10 Aug 2023 22:45:00 +0530 Subject: feat: adds simple evaluator --- src/utils/parser-comb.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/utils/parser-comb.ts') diff --git a/src/utils/parser-comb.ts b/src/utils/parser-comb.ts index 49f633e..e0665f6 100644 --- a/src/utils/parser-comb.ts +++ b/src/utils/parser-comb.ts @@ -1,16 +1,5 @@ -import { Enum, constructors, match } from './adt'; - -export type Result = Enum<{ Ok: V, Err: E }> -export const Result = constructors>() - -export const mapResult = (res: Result, fn: (_: A) => B): Result => - chainResult(res, a => Result.Ok(fn(a))) - -export const chainResult = (res: Result, fn: (_: A) => Result): Result => - match(res, { - Ok: a => fn(a), - Err: e => Result.Err(e), - }); +import { match } from './adt'; +import { Result, mapResult, chainResult } from './result'; export type ParseResult = Result<{ value: T, input: string }, { error: string, input: string }>; -- cgit v1.3.1