Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Right<L, R>

Type parameters

  • L

  • R

Hierarchy

  • Right

Implements

Index

Constructors

constructor

  • new Right<L, R>(value: R): Right<L, R>

Properties

Private value

value: R

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>(_: (value: L) => U, rightFn: (value: R) => U): U
  • Type parameters

    • U

    Parameters

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

          • value: L

          Returns U

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

          • value: R

          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
  • Type parameters

    • U

    Parameters

    • _defaultValue: U

    Returns R

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(_: (value: R) => R): Either<L, R>
  • Parameters

    • _: (value: R) => R
        • (value: R): R
        • Parameters

          • value: R

          Returns R

    Returns Either<L, R>

orElse

  • orElse<U>(_f: (value: L) => U): R | U
  • Type parameters

    • U

    Parameters

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

          • value: L

          Returns U

    Returns R | 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