Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KoconutPair<FirstType, SecondType>

Koconut Wrapper class for Pair

see
-- Base --
Pair, Entry, KoconutPair

-- Protocol --
KoconutEquatable

Type parameters

  • FirstType

    Check for Pair

  • SecondType

    Check for Pair

Hierarchy

  • KoconutPrimitive<Pair<FirstType, SecondType>>
    • KoconutPair

Implements

Index

Constructors

Other Methods

Processor Methods

Constructors

constructor

  • new KoconutPair(first?: FirstType | null, second?: SecondType | null): KoconutPair

Other Methods

equalsTo

Processor Methods

also

  • also(block: (data: Pair<FirstType, SecondType>) => void | Promise<void>): Promise<Pair<FirstType, SecondType> | null>
  • Processes all the chained objects and calls the specified function block with the result value as its argument and returns the original result.

    since

    1.0.10

    example
    import { KoconutArray } from 'koconut'
    
    const mainProcess = async () => {
      const koconutNumbers = KoconutArray.of(1,2,3,4,5)
    
      const moreNumbers = await koconutNumbers
                              .also(result => {
                                  result.push(6)
                                  result.push(7)
                                  result.push(8)
                              })
      console.log(moreNumbers)
      // ↑ [1, 2, 3, 4, 5, 6, 7, 8]
    }
    mainProcess()

    Parameters

    • block: (data: Pair<FirstType, SecondType>) => void | Promise<void>

      A callback function that accepts an argument.

        • (data: Pair<FirstType, SecondType>): void | Promise<void>
        • Parameters

          • data: Pair<FirstType, SecondType>

          Returns void | Promise<void>

    Returns Promise<Pair<FirstType, SecondType> | null>

let

  • let<ReturnType>(block: (data: Pair<FirstType, SecondType>) => ReturnType | Promise<ReturnType>): Promise<ReturnType>
  • Processes all the chained objects and calls the specified function block with the result value as its argument and returns the final result of the block.

    since

    1.0.10

    example
    import { KoconutArray } from 'koconut'
    
    const mainProcess = async () => {
      const koconutNumbers = KoconutArray.of(1,2,3,4,5)
    
      const firstNumberPlus2 = await koconutNumbers
                              .first()
                              .let(result => result + 2)
      console.log(firstNumber)
      // ↑ 3
    }
    mainProcess()

    Type parameters

    • ReturnType

    Parameters

    • block: (data: Pair<FirstType, SecondType>) => ReturnType | Promise<ReturnType>

      A callback function that accepts an argument. The method calls the block and returns its result.

        • (data: Pair<FirstType, SecondType>): ReturnType | Promise<ReturnType>
        • Parameters

          • data: Pair<FirstType, SecondType>

          Returns ReturnType | Promise<ReturnType>

    Returns Promise<ReturnType>

process

  • process(): Promise<void>
  • Processes all the chained objects ane returns Promise<void>.

    since

    1.0.10

    example
    import { KoconutArray } from 'koconut'
    
    const mainProcess = async () => {
      const koconutNumbers = KoconutArray.of(1,2,3,4,5)
    
      await koconutNumbers
                  .forEach(console.log)
                  .process()
      // ↑ 1 2 3 4 5
    }
    mainProcess()

    Returns Promise<void>

retrieve

  • retrieve(): Promise<KoconutPair<FirstType, SecondType>>
  • Processes all the chained object and returns original KoconutPair instance.

    since

    1.0.15

    example
    const koconutPair = await new KoconutPair(0, 1)
                                        .retrieve()
    
    console.log(koconutPair)
    // ↑ KoconutPair {
    //   isValidated: true,
    //   data: Pair { firstElement: 0, secondElement: 1 }
    // }

    Returns Promise<KoconutPair<FirstType, SecondType>>

yield

  • yield(): Promise<Pair<FirstType, SecondType>>
  • Processes all the chained objects and return the result.

    since

    1.0.10

    example
    import { KoconutArray } from 'koconut'
    
    const mainProcess = async () => {
      const koconutNumbers = KoconutArray.of(1,2,3,4,5)
    
      const firstNumber = await koconutNumbers
                                          .first()
                                          .yield()
      console.log(firstNumber)
      // ↑ 1
    }
    mainProcess()

    Returns Promise<Pair<FirstType, SecondType>>

Generated using TypeDoc