Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "index"

Index

Type aliases

ParseResult

ParseResult<Error, R>: Either<Error, R>

Type parameters

  • Error

  • R

Parser

Parser<R, E, O>: object

Type parameters

  • R

  • E

  • O

Type declaration

ParserReturnType

ParserReturnType<P>: ParserReturnType<P>

Type parameters

  • P

PredicateMismatchError

PredicateMismatchError: object

Type declaration

  • _tag: "PredicateMismatch"
  • customMessage: string
  • value: unknown

URI

URI: "Parser"

Variables

Const URI

URI: "Parser" = "Parser" as const

Const ap

ap: ap = parserMonad.ap

Const chain

chain: chain = parserMonad.chain

Const map

map: map = parserMonad.map

Const of

of: of = parserMonad.of

Const p

p: predicate = predicate

Const parser

parser: object = {...parserMonad,mapError} as const

Type declaration

Const parserApplicative

parserApplicative: object = {...parserFunctor,of: <A, E, C>(a: A): Parser<A, E, C> => from((_: C) => right(a)),ap: <A, B, E, C>(fab: Parser<(a: A) => B, E, C>, a: Parser<A, E, C>): Parser<B, E, C> =>from((o: C) => E.ap(a.runParser(o))(fab.runParser(o)))} as const

Type declaration

  • ap: function
    • Type parameters

      • A

      • B

      • E

      • C

      Parameters

      Returns Parser<B, E, C>

  • of: function
    • of<A, E, C>(a: A): Parser<A, E, C>
    • Type parameters

      • A

      • E

      • C

      Parameters

      • a: A

      Returns Parser<A, E, C>

Const parserFunctor

parserFunctor: object = {URI,map: <A, E, B, C>(v: Parser<A, E, C>, f: (a: A) => B): Parser<B, E, C> => from((o: C) => E.map(f)(v.runParser(o)))} as const

Type declaration

  • URI: "Parser"
  • map: function
    • map<A, E, B, C>(v: Parser<A, E, C>, f: function): Parser<B, E, C>
    • Type parameters

      • A

      • E

      • B

      • C

      Parameters

      • v: Parser<A, E, C>
      • f: function
          • (a: A): B
          • Parameters

            • a: A

            Returns B

      Returns Parser<B, E, C>

Const parserMonad

parserMonad: object = {...parserApplicative,chain: <A, B, E, C>(fa: Parser<A, E, C>, afb: (a: A) => Parser<B, E, C>): Parser<B, E, C> =>from((o: C) => E.chain((a: A): Either<E, B> => afb(a).runParser(o))(fa.runParser(o)))} as const

Type declaration

  • chain: function
    • chain<A, B, E, C>(fa: Parser<A, E, C>, afb: function): Parser<B, E, C>
    • Type parameters

      • A

      • B

      • E

      • C

      Parameters

      • fa: Parser<A, E, C>
      • afb: function
          • Parameters

            • a: A

            Returns Parser<B, E, C>

      Returns Parser<B, E, C>

Functions

both

  • Run two parsers, failing if either fail and succeeding when both succeed.

    Type parameters

    • A

    • B

    • E

    • I

    Parameters

    Returns Parser<[A, B], E, I>

Const compose

  • Type parameters

    • A

    • B

    • C

    • E

    • D

    Parameters

    Returns Parser<C, E | D, A>

fail

  • fail<R, E, B>(error: E): Parser<never, E, B>
  • Type parameters

    • R

    • E

    • B

    Parameters

    • error: E

    Returns Parser<never, E, B>

Const from

  • from<R, E, O>(parser: function): Parser<R, E, O>
  • Type parameters

    • R

    • E

    • O

    Parameters

    Returns Parser<R, E, O>

Const fromResult

  • fromResult<R, E, I>(e: Either<E, R>): Parser<R, E, I>
  • Type parameters

    • R

    • E

    • I

    Parameters

    • e: Either<E, R>

    Returns Parser<R, E, I>

isFailure

  • isFailure<R, E>(result: ParseResult<E, R>): result is Left<E>
  • Type parameters

    • R

    • E

    Parameters

    Returns result is Left<E>

isSuccess

  • isSuccess<R, E>(result: ParseResult<E, R>): result is Right<R>
  • Type parameters

    • R

    • E

    Parameters

    Returns result is Right<R>

Const mapError

  • mapError<A, E, R, D>(parser: Parser<A, E, R>, ed: function): Parser<A, D, R>
  • Type parameters

    • A

    • E

    • R

    • D

    Parameters

    • parser: Parser<A, E, R>
    • ed: function
        • (e: E): D
        • Parameters

          • e: E

          Returns D

    Returns Parser<A, D, R>

or

  • or<A, B, I>(fst: Parser<A, string, I>, snd: Parser<B, string, I>): Parser<A | B, string, I>
  • Run two parsers on an unknown, succeeding if either succeed and failing if both fail.

    Type parameters

    • A

    • B

    • I

    Parameters

    Returns Parser<A | B, string, I>

Const predicate

  • predicate<K, I>(type: K): (Anonymous function)
  • Type parameters

    Parameters

    • type: K

    Returns (Anonymous function)

recursive

  • recursive<R, E, I>(body: Lazy<Parser<R, E, I>>): Parser<R, E, I>
  • Due to javascript not being a "lazy" language, we have to embed recursive references to parsers in a thunk.

    Type parameters

    • R

    • E

    • I

    Parameters

    • body: Lazy<Parser<R, E, I>>

      A thunk that returns a parser, possibly one that references itself.

    Returns Parser<R, E, I>

runParser

  • runParser<R, E, I>(parser: Parser<R, E, I>, input: I): Left<E> | Right<R>
  • Given an object of type B, parse out an object of type R with the possibility of errors of type E

    Type parameters

    • R

    • E

    • I

    Parameters

    • parser: Parser<R, E, I>
    • input: I

    Returns Left<E> | Right<R>

runParserEx

  • runParserEx<Result, Error, Input>(parser: Parser<Result, Error, Input>, input: Input): Result | never
  • Given an anonymous object and a parser, return the object or throw an exception if parsing fails.

    Type parameters

    • Result

    • Error

    • Input

    Parameters

    • parser: Parser<Result, Error, Input>

      the parser to run

    • input: Input

      value to parse from

    Returns Result | never

succeed

  • succeed<R, E, B>(result: R): Parser<R, never, B>
  • Type parameters

    • R

    • E

    • B

    Parameters

    • result: R

    Returns Parser<R, never, B>

Generated using TypeDoc