Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Left<L, R>

Type parameters

  • L

  • R

Hierarchy

  • Left

Implements

Index

Constructors

constructor

  • new Left<L, R>(value: L): Left<L, R>
  • Type parameters

    • L

    • R

    Parameters

    • value: L

    Returns Left<L, R>

Properties

Private value

value: L

Methods

caseOf

  • caseOf<U>(matcher: CaseOf<L, R, U>): U
  • Returns false if it's Left and true otherwise.

    import { Either } from 'monad-maniac'
    
    const left = Either.left<string, number>('Some Error')
    const right = Either.right<string, number>(150)
    
    const matcher: Either.CaseOf<string, number, number> = {
      Right: (x) => x * 2,
      Left: (message) => message.length,
    }
    
    const resultLeft = left.caseOf(matcher) // 10
    const resultRight = right.caseOf(matcher) // 300
    

    Type parameters

    • U

    Parameters

    Returns U

cata

  • cata<U>(leftFn: (value: L) => U): U
  • Type parameters

    • U

    Parameters

    • leftFn: (value: L) => U
        • (value: L): U
        • Parameters

          • value: L

          Returns U

    Returns U

chain

filter

  • filter(_predicate: (value: R) => boolean): Either<L | R, R>
  • Parameters

    • _predicate: (value: R) => boolean
        • (value: R): boolean
        • Parameters

          • value: R

          Returns boolean

    Returns Either<L | R, R>

get

  • get(): L | R
  • Just returns value from Right or Left

    import { Either } from 'monad-maniac'
    
    const left = Either.left<number, number>(300)
    const right = Either.right<number, number>(150)
    
    const resultLeft = left.get() // 300
    const resultRight = right.get() // 150
    

    Returns L | R

getOrElse

  • getOrElse<U>(defaultValue: U): R | U
  • Type parameters

    • U

    Parameters

    • defaultValue: U

    Returns R | U

isLeft

  • isLeft(): boolean
  • Returns true if it's Left and false otherwise.

    import { Either } from 'monad-maniac'
    
    const left = Either.left<number, number>(300)
    const right = Either.right<number, number>(150)
    
    const resultLeft = left.isLeft() // true
    const resultRight = right.isLeft() // false
    

    Returns boolean

isRight

  • isRight(): boolean
  • Returns false if it's Left and true otherwise.

    import { Either } from 'monad-maniac'
    
    const left = Either.left<number, number>(300)
    const right = Either.right<number, number>(150)
    
    const resultLeft = left.isRight() // false
    const resultRight = right.isRight() // true
    

    Returns boolean

map

  • map<U>(_f: (value: R) => U): Either<L, U>
  • Type parameters

    • U

    Parameters

    • _f: (value: R) => U
        • (value: R): U
        • Parameters

          • value: R

          Returns U

    Returns Either<L, U>

or

  • or(f: () => R): Either<L, R>

orElse

  • orElse<U>(f: (value: L) => U): U
  • Type parameters

    • U

    Parameters

    • f: (value: L) => U
        • (value: L): U
        • Parameters

          • value: L

          Returns U

    Returns U

toMaybe

  • Converting Either to Maybe. If value in Left will returns Nothing, else returns result Maybe.of for value from Right.

    import { Either } from 'monad-maniac'
    
    const left = Either.left<string, number>('Some Error')
    const right = Either.right<string, number>(150)
    const rightVoid = Either.right<string, number | void>(undefined)
    
    const resultLeft = left.toMaybe() // Nothing()
    const resultRight = right.toMaybe() // Just(150)
    const resultRightVoid = rightVoid.toMaybe() // Nothing()
    

    Returns Shape<R>

toString

  • toString(): string
  • Returns Left or Right as string: Left(left value) or Right(right value).

    import { Either } from 'monad-maniac'
    
    const left = Either.left<number, number>(300)
    const right = Either.right<number, number>(150)
    
    const resultLeft = left.toString() // Left(300)
    const resultRight = right.toString() // Right(150)
    

    Returns string

Generated using TypeDoc