Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • DataType

Hierarchy

  • KoconutCollection<DataType, Set<DataType>>
    • KoconutSet

Implements

  • KoconutYieldable<Set<DataType>>

Index

Constructors

Accumulator Methods

Calculator Methods

Caster Methods

Creator Methods

Inspector Methods

Iterator Methods

Manipulator Methods

Other Methods

Processor Methods

Selector Methods

Transformer Methods

Constructors

constructor

  • new KoconutSet(set?: Iterable<DataType> | null): KoconutSet
  • Creates a new instance from iterable object.

    since

    1.0.10

    example
    const numbers = Array.of(1,2,3,4,5)
    const koconutNumbers = new KoconutSet(numbers)
    // ↑ This is a Koconut number set consists of 1 to 5.
    
    const emptyNumberSet = new KoconutSet<number>()
    // ↑ This is an empty Koconut number set.

    Parameters

    • Default value set: Iterable<DataType> | null = null

      An array-like iterable object to convert to a KoconutSet.

    Returns KoconutSet

Accumulator Methods

fold

  • fold<ResultDataType>(initial: ResultDataType, operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutPrimitive<ResultDataType>
  • Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const sumOfArray = await koconutArray
                    .fold(
                        0,
                        (acc, eachNumber) => acc + eachNumber
                    )
                    .yield()
    console.log(sumOfArray)
    // ↑ 15
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const multiplesOfSet = await koconutSet
                    .fold(
                        1,
                        async (acc, eachNumber) => acc * eachNumber
                    )
                    .yield()
    console.log(multiplesOfSet)
    // ↑ 120

    Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType

      A value to use as the first argument to the first call of the operation.

    • operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts one argument. The operation accumulates callback's return value. It's accumulated value previously returned in the last invocation of the callback or initial value. The method calls the operation one time for each element in object.

        • (acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the operation. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType>

foldIndexed

  • foldIndexed<ResultDataType>(initial: ResultDataType, operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutPrimitive<ResultDataType>
  • Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const sumOfNumberAndIndexInArray = await koconutArray
                    .foldIndexed(
                        0,
                        (index, acc, eachNumber) => index + acc + eachNumber
                    )
                    .yield()
    console.log(sumOfNumberAndIndexInArray)
    // ↑ 25
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const multiplesOfNumberAndIndexInSet = await koconutSet
                    .foldIndexed(
                        1,
                        async (index, acc, eachNumber) => index * acc * eachNumber
                    )
                    .yield()
    console.log(multiplesOfNumberAndIndexInSet)
    // ↑ 0

    Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType

      A value to use as the first argument to the first call of the operation.

    • operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts one argument. The operation accumulates callback's return value. It's accumulated value previously returned in the last invocation of the callback or initial value. The method calls the operation one time for each element and index in object.

        • (index: number, acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • index: number
          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the operation. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType>

Calculator Methods

count

  • count(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<number>
  • Returns the number of the elements matching the given predicate. If the predicate is ommitted it'll returns the whole number of elements.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const numberOfAllArrayElements = await koconutArray
                                          .count()
                                          .yield()
    console.log(numberOfAllArrayElements)
    // ↑ 5
    
    const numberOfArrayElementsHigherThan2 = await koconutArray
                                              .count(eachNumber => eachNumber > 2)
                                              .yield()
    console.log(numberOfArrayElementsHigherThan2)
    // ↑ 3 -- i.e. [3, 4, 5]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const numberOfAllSetElements = await koconutSet
                                          .count()
                                          .yield()
    console.log(numberOfAllSetElements)
    // ↑ 5
    
    const numberOfOddSetElements = await koconutSet
                                          .count(eachNumber => eachNumber % 2 == 1)
                                          .yield()
    console.log(numberOfOddSetElements)
    // ↑ 3 -- i.e. [1, 3, 5]
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3)
                      .associateWith(eachNumber => eachNumber * 2)
                      // ↑ Map { 1 => 2,
                      //         2 => 4,
                      //         3 => 6 }
    
    const numberOfAllMapEntries = await koconutMap
                                      .count()
                                      .yield()
    console.log(numberOfAllMapEntries)
    // ↑ 3
    
    const numberOfMapEntriesValueHigherThan5 = await koconutMap
                                                  .count(eachEntry => eachEntry.value > 5)
                                                  .yield()
    console.log(numberOfMapEntriesValueHigherThan5)
    // ↑ 1 -- i.e. Entry { 3, 6 }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const numberOfArrayElementsLessThan3 = await koconutArray2
                                          .count(async eachNumber => eachNumber < 3)
                                          .yield()
    console.log(numberOfArrayElementsLessThan3)
    // ↑ 2 -- i.e. [1, 2]
    
    const numberOfEvenArrayElements = await koconutArray2
                                      .count(eachNumber => new Promise(resolve => {
                                          resolve(eachNumber % 2 == 0)
                                      }))
                                      .yield()
    console.log(numberOfEvenArrayElements)
    // ↑ 2 -- i.e. [2, 4]

    Parameters

    • Default value predicate: ((element: DataType) => boolean | Promise<boolean>) | null = null

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<number>

maxBy

  • Returns the first element yielding the largest value of the given function or throws KoconutNoSuchElementException if there are no elements.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    deprecated

    Use maxByOrNull instead.

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const largestNumberOfArray = await koconutArray
                                  .maxBy(eachNumber => eachNumber)
                                  .yield()
    console.log(largestNumberOfArray)
    // ↑ 5
    
    try {
      await koconutArray
              .filter(eachNumber => eachNumber > 10)
              .maxBy(eachNumber => eachNumber)
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const lognestStringOfSet = await koconutSet
                                  .maxBy(eachString => eachString.length)
                                  .yield()
    console.log(lognestStringOfSet)
    // ↑ abc
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1, 12, 123)
                      .associateWith(eachNumber => eachNumber.toString())
    
    const longestDigitsEntryOfMap = await koconutMap
                                          .maxBy(eachEntry => eachEntry.value.length)
                                          .yield()
    console.log(longestDigitsEntryOfMap)
    // ↑ Entry { keyElement: 123, valueElement: '123' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(19,27,32)
    
    const largestNumberOfArray2 = await koconutArray2
                                      .maxBy(async eachNumber => eachNumber)
                                      .yield()
    console.log(largestNumberOfArray2)
    // ↑ 32
    
    const largest1sDigitNumberOfArray2 = await koconutArray2
                                          .maxBy(eachNumber => new Promise(resolve => {
                                              resolve(eachNumber % 10)
                                          }))
                                          .yield()
    console.log(largest1sDigitNumberOfArray2)
    // ↑ 19

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

maxByOrNull

  • maxByOrNull(selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element yielding the largest value of the given function or null if there are no elements.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const largestNumberOfArray = await koconutArray
                                  .maxByOrNull(eachNumber => eachNumber)
                                  .yield()
    console.log(largestNumberOfArray)
    // ↑ 5
    
    
    const largestNumberOfEmptyArray = await koconutArray
                                    .filter(eachNumber => eachNumber > 10)
                                    .maxByOrNull(eachNumber => eachNumber)
                                    .yield()
    console.log(largestNumberOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const lognestStringOfSet = await koconutSet
                                  .maxByOrNull(eachString => eachString.length)
                                  .yield()
    console.log(lognestStringOfSet)
    // ↑ abc
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1, 12, 123)
                      .associateWith(eachNumber => eachNumber.toString())
    
    const longestDigitsEntryOfMap = await koconutMap
                                          .maxByOrNull(eachEntry => eachEntry.value.length)
                                          .yield()
    console.log(longestDigitsEntryOfMap)
    // ↑ Entry { keyElement: 123, valueElement: '123' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(19,27,32)
    
    const largestNumberOfArray2 = await koconutArray2
                                      .maxByOrNull(async eachNumber => eachNumber)
                                      .yield()
    console.log(largestNumberOfArray2)
    // ↑ 32
    
    const largest1sDigitNumberOfArray2 = await koconutArray2
                                          .maxByOrNull(eachNumber => new Promise(resolve => {
                                              resolve(eachNumber % 10)
                                          }))
                                          .yield()
    console.log(largest1sDigitNumberOfArray2)
    // ↑ 19

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

maxOf

  • maxOf(selector: (element: DataType) => number | Promise<number>, thisArg: any): KoconutPrimitive<number>
  • maxOf(selector: (element: DataType) => string | Promise<string>, thisArg: any): KoconutPrimitive<string>
  • maxOf<ComparableType>(selector: (element: DataType) => ComparableType | Promise<ComparableType>, thisArg: any): KoconutPrimitive<ComparableType>
  • Returns the largest value among all values produced by selector function applied to each element in the collection or throws KoconutNoSuchElementException if there are no elements.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,7,9)
    
    const largestRemainderNumberDividedBy5OfArray = await koconutArray
                                                  .maxOf(eachNumber => eachNumber % 5)
                                                  .yield()
    console.log(largestRemainderNumberDividedBy5OfArray)
    // ↑ 4
    
    try {
      await koconutArray
              .filter(eachNumber => eachNumber > 10)
              .maxOf(eachNumber => eachNumber % 5)
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const longestStringLengthOfSet = await koconutSet
                                  .maxOf(eachString => eachString.length)
                                  .yield()
    console.log(longestStringLengthOfSet)
    // ↑ 3
    
    class ComparableString implements KoconutComparable{
      str : string
      constructor(str : string) {
          this.str = str
      }
      // Override
      compareTo(other : ComparableString) : number {
          return this.str.length - other.str.length
      }
    }
    const maxComparableString = await koconutSet
                              .maxOf(eachString => new ComparableString(eachString))
                              .yield()
    console.log(maxComparableString)
    // ↑ ComparableString { str: 'abc' }
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthOfMap = await koconutMap
                                      .maxOf(eachEntry => eachEntry.key)
                                      .yield()
    console.log(longestStringLengthOfMap)
    // ↑ 3
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                              .maxOf(async eachNumber => eachNumber)
                              .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitOfArray2 = await koconutArray2
                              .maxOf(eachNumber => new Promise(resolve => {
                                  resolve(eachNumber % 10)
                              }))
                              .yield()
    console.log(largest1sDigitOfArray2)
    // ↑ 5

    Parameters

    • selector: (element: DataType) => number | Promise<number>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): number | Promise<number>
        • Parameters

          • element: DataType

          Returns number | Promise<number>

    • thisArg: any

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<number>

  • Parameters

    • selector: (element: DataType) => string | Promise<string>
        • (element: DataType): string | Promise<string>
        • Parameters

          • element: DataType

          Returns string | Promise<string>

    • thisArg: any

    Returns KoconutPrimitive<string>

  • Type parameters

    Parameters

    • selector: (element: DataType) => ComparableType | Promise<ComparableType>
        • (element: DataType): ComparableType | Promise<ComparableType>
        • Parameters

          • element: DataType

          Returns ComparableType | Promise<ComparableType>

    • thisArg: any

    Returns KoconutPrimitive<ComparableType>

maxOfOrNull

  • maxOfOrNull(selector: (element: DataType) => number | Promise<number>): KoconutPrimitive<number | null>
  • maxOfOrNull(selector: (element: DataType) => number | Promise<number>, thisArg: any): KoconutPrimitive<number | null>
  • maxOfOrNull(selector: (element: DataType) => string | Promise<string>): KoconutPrimitive<string | null>
  • maxOfOrNull(selector: (element: DataType) => string | Promise<string>, thisArg: any): KoconutPrimitive<string | null>
  • maxOfOrNull<ComparableType>(selector: (element: DataType) => ComparableType | Promise<ComparableType>): KoconutPrimitive<ComparableType | null>
  • maxOfOrNull<ComparableType>(selector: (element: DataType) => ComparableType | Promise<ComparableType>, thisArg: any): KoconutPrimitive<ComparableType | null>
  • Returns the largest value among all values produced by selector function applied to each element in the collection or null if there are no elements.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,7,9)
    
    const largestRemainderNumberDividedBy5OfArray = await koconutArray
                                                  .maxOfOrNull(eachNumber => eachNumber % 5)
                                                  .yield()
    console.log(largestRemainderNumberDividedBy5OfArray)
    // ↑ 4
    
    const largestRemainderNumberDividedBy5OfEmptyArray = await koconutArray
                                          .filter(eachNumber => eachNumber > 10)
                                          .maxOfOrNull(eachNumber => eachNumber % 5)
                                          .yield()
    console.log(largestRemainderNumberDividedBy5OfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const longestStringLengthOfSet = await koconutSet
                                  .maxOfOrNull(eachString => eachString.length)
                                  .yield()
    console.log(longestStringLengthOfSet)
    // ↑ 3
    
    class ComparableString implements KoconutComparable{
      str : string
      constructor(str : string) {
          this.str = str
      }
      // Override
      compareTo(other : ComparableString) : number {
          return this.str.length - other.str.length
      }
    }
    const maxComparableString = await koconutSet
                              .maxOfOrNull(eachString => new ComparableString(eachString))
                              .yield()
    console.log(maxComparableString)
    // ↑ ComparableString { str: 'abc' }
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthOfMap = await koconutMap
                                      .maxOfOrNull(eachEntry => eachEntry.key)
                                      .yield()
    console.log(longestStringLengthOfMap)
    // ↑ 3
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                              .maxOfOrNull(async eachNumber => eachNumber)
                              .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitOfArray2 = await koconutArray2
                              .maxOfOrNull(eachNumber => new Promise(resolve => {
                                  resolve(eachNumber % 10)
                              }))
                              .yield()
    console.log(largest1sDigitOfArray2)
    // ↑ 5

    Parameters

    • selector: (element: DataType) => number | Promise<number>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): number | Promise<number>
        • Parameters

          • element: DataType

          Returns number | Promise<number>

    Returns KoconutPrimitive<number | null>

  • Parameters

    • selector: (element: DataType) => number | Promise<number>
        • (element: DataType): number | Promise<number>
        • Parameters

          • element: DataType

          Returns number | Promise<number>

    • thisArg: any

    Returns KoconutPrimitive<number | null>

  • Parameters

    • selector: (element: DataType) => string | Promise<string>
        • (element: DataType): string | Promise<string>
        • Parameters

          • element: DataType

          Returns string | Promise<string>

    Returns KoconutPrimitive<string | null>

  • Parameters

    • selector: (element: DataType) => string | Promise<string>
        • (element: DataType): string | Promise<string>
        • Parameters

          • element: DataType

          Returns string | Promise<string>

    • thisArg: any

    Returns KoconutPrimitive<string | null>

  • Type parameters

    Parameters

    • selector: (element: DataType) => ComparableType | Promise<ComparableType>
        • (element: DataType): ComparableType | Promise<ComparableType>
        • Parameters

          • element: DataType

          Returns ComparableType | Promise<ComparableType>

    Returns KoconutPrimitive<ComparableType | null>

  • Type parameters

    Parameters

    • selector: (element: DataType) => ComparableType | Promise<ComparableType>
        • (element: DataType): ComparableType | Promise<ComparableType>
        • Parameters

          • element: DataType

          Returns ComparableType | Promise<ComparableType>

    • thisArg: any

    Returns KoconutPrimitive<ComparableType | null>

maxOfWith

  • maxOfWith<ResultDataType>(selector: (element: DataType) => ResultDataType | Promise<ResultDataType>, comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>, selectorThisArg?: any, comparatorThisArg?: any): KoconutPrimitive<ResultDataType>
  • Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection all throws KoconutNoSuchElementException if elements are empty.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of("1", "2", "3", "4", "5")
    
    const largestNumberedStringOfArray = await koconutArray
                                      .maxOfWith(
                                          parseInt,
                                          (front, rear) => front - rear
                                      )
                                      .yield()
    console.log(largestNumberedStringOfArray)
    // ↑ 5
    
    try {
      await koconutArray
              .filter(eachString => eachString.length > 2)
              .maxOfWith(
                  parseInt,
                  (front, rear) => front - rear
              )
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No string in "1" to "5" is logner than 2.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const lognestStringLengthOfSet = await koconutSet
                                  .maxOfWith(
                                      eachString => eachString.length,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(lognestStringLengthOfSet)
    // ↑ 3
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthOfMap = await koconutMap
                                      .maxOfWith(
                                          eachEntry => eachEntry.key,
                                          (front, rear) => front - rear
                                      )
                                      .yield()
    console.log(longestStringLengthOfMap)
    // ↑ 3
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                                  .maxOfWith(
                                      async eachNumber => eachNumber,
                                      async (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitOfArray2 = await koconutArray2
                                  .maxOfWith(
                                      (eachNumber) => new Promise<number>(resolve => {
                                          resolve(eachNumber % 10)
                                      }),
                                      (front, rear) => new Promise(resolve => {
                                          resolve(front - rear)
                                      })
                                  )
                                  .yield()
    console.log(largest1sDigitOfArray2)
    // ↑ 5

    Type parameters

    • ResultDataType

    Parameters

    • selector: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: ResultDataType, rear: ResultDataType): number | Promise<number>
        • Parameters

          • front: ResultDataType
          • rear: ResultDataType

          Returns number | Promise<number>

    • Default value selectorThisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    • Default value comparatorThisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType>

maxOfWithOrNull

  • maxOfWithOrNull<ResultDataType>(selector: (element: DataType) => ResultDataType | Promise<ResultDataType>, comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>, selectorThisArg?: any, comparatorThisArg?: any): KoconutPrimitive<ResultDataType | null>
  • Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection or null if elements are empty.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of("1", "2", "3", "4", "5")
    
    const largestNumberedStringOfArray = await koconutArray
                                      .maxOfWithOrNull(
                                          parseInt,
                                          (front, rear) => front - rear
                                      )
                                      .yield()
    console.log(largestNumberedStringOfArray)
    // ↑ 5
    
    const largestNumberedStringOfEmptyArray = await koconutArray
                              .filter(eachString => eachString.length > 2)
                              .maxOfWithOrNull(
                                  parseInt,
                                  (front, rear) => front - rear
                              )
                              .yield()
    console.log(largestNumberedStringOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const lognestStringLengthOfSet = await koconutSet
                                  .maxOfWithOrNull(
                                      eachString => eachString.length,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(lognestStringLengthOfSet)
    // ↑ 3
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthOfMap = await koconutMap
                                      .maxOfWithOrNull(
                                          eachEntry => eachEntry.key,
                                          (front, rear) => front - rear
                                      )
                                      .yield()
    console.log(longestStringLengthOfMap)
    // ↑ 3
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                                  .maxOfWithOrNull(
                                      async eachNumber => eachNumber,
                                      async (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitOfArray2 = await koconutArray2
                                  .maxOfWithOrNull(
                                      (eachNumber) => new Promise<number>(resolve => {
                                          resolve(eachNumber % 10)
                                      }),
                                      (front, rear) => new Promise(resolve => {
                                          resolve(front - rear)
                                      })
                                  )
                                  .yield()
    console.log(largest1sDigitOfArray2)
    // ↑ 5

    Type parameters

    • ResultDataType

    Parameters

    • selector: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: ResultDataType, rear: ResultDataType): number | Promise<number>
        • Parameters

          • front: ResultDataType
          • rear: ResultDataType

          Returns number | Promise<number>

    • Default value selectorThisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    • Default value comparatorThisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType | null>

maxWith

  • maxWith(comparator: (front: DataType, rear: DataType) => number | Promise<number>, thisArg?: any): KoconutPrimitive<DataType>
  • Returns the first element having the largest value according to the provided comparator or throws KoconutNoSuchElementException if elements are empty.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const largestNumberOfArray = await koconutArray
                                      .maxWith((front, rear) => front - rear)
                                      .yield()
    console.log(largestNumberOfArray)
    // ↑ 5
    
    try {
      await koconutArray
              .filter(eachNumber => eachNumber > 10)
              .maxWith((front, rear) => front - rear)
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc", "abcd")
    
    const longestStringLengthOfSet = await koconutSet
                                          .maxWith((front, rear) => front.length - rear.length)
                                          .yield()
    console.log(longestStringLengthOfSet)
    // ↑ abcd
    
    // Case 3
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthEntryOfMap = await koconutMap
                                      .maxWith((front, rear) => front.key - rear.key)
                                      .yield()
    console.log(longestStringLengthEntryOfMap)
    // ↑ Entry { keyElement: 3, valueElement: 'abc' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                        .maxWith(async (front, rear) => front - rear)
                        .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitNumberOfArray2 = await koconutArray2
                          .maxWith((front, rear) => new Promise(resolve => {
                              resolve(front % 10 - rear % 10)
                          }))
                          .yield()
    console.log(largest1sDigitNumberOfArray2)
    // ↑ 45

    Parameters

    • comparator: (front: DataType, rear: DataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: DataType, rear: DataType): number | Promise<number>
        • Parameters

          • front: DataType
          • rear: DataType

          Returns number | Promise<number>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

maxWithOrNull

  • maxWithOrNull(comparator: (front: DataType, rear: DataType) => number | Promise<number>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element having the largest value according to the provided comparator or null if elements are empty.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const largestNumberOfArray = await koconutArray
                                      .maxWithOrNull((front, rear) => front - rear)
                                      .yield()
    console.log(largestNumberOfArray)
    // ↑ 5
    
    const largestNumberOfEmptyArray = await koconutArray
                                     .filter(eachNumber => eachNumber > 10)
                                     .maxWithOrNull((front, rear) => front - rear)
                                     .yield()
    console.log(largestNumberOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc", "abcd")
    
    const longestStringLengthOfSet = await koconutSet
                                          .maxWithOrNull((front, rear) => front.length - rear.length)
                                          .yield()
    console.log(longestStringLengthOfSet)
    // ↑ abcd
    
    // Case 3
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                      .associate(eachString => [eachString.length, eachString])
    
    const longestStringLengthEntryOfMap = await koconutMap
                                      .maxWithOrNull((front, rear) => front.key - rear.key)
                                      .yield()
    console.log(longestStringLengthEntryOfMap)
    // ↑ Entry { keyElement: 3, valueElement: 'abc' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const largestNumberOfArray2 = await koconutArray2
                        .maxWithOrNull(async (front, rear) => front - rear)
                        .yield()
    console.log(largestNumberOfArray2)
    // ↑ 51
    
    const largest1sDigitNumberOfArray2 = await koconutArray2
                          .maxWithOrNull((front, rear) => new Promise(resolve => {
                              resolve(front % 10 - rear % 10)
                          }))
                          .yield()
    console.log(largest1sDigitNumberOfArray2)
    // ↑ 45

    Parameters

    • comparator: (front: DataType, rear: DataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: DataType, rear: DataType): number | Promise<number>
        • Parameters

          • front: DataType
          • rear: DataType

          Returns number | Promise<number>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

minBy

  • Returns the first element yielding the samllest value of the given function or throws KoconutNoSuchElementException if there are no elements.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    deprecated

    Use minByOrNull instead.

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const smallestNumberOfArray = await koconutArray
                              .minBy(eachNumber => eachNumber)
                              .yield()
    console.log(smallestNumberOfArray)
    // ↑ 1
    
    try {
    await koconutArray
          .filter(eachNumber => eachNumber > 10)
          .minBy(eachNumber => eachNumber)
          .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringOfSet = await koconutSet
                              .minBy(eachString => eachString.length)
                              .yield()
    console.log(shortestStringOfSet)
    // ↑ a
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1, 12, 123)
                  .associateWith(eachNumber => eachNumber.toString())
    
    const shortestDigitsEntryOfMap = await koconutMap
                                      .minBy(eachEntry => eachEntry.value.length)
                                      .yield()
    console.log(shortestDigitsEntryOfMap)
    // ↑ Entry { keyElement: 1, valueElement: '1' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(19,27,32)
    
    const smallestNumberOfArray2 = await koconutArray2
                                  .minBy(async eachNumber => eachNumber)
                                  .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 19
    
    const smallest1sDigitNumberOfArray2 = await koconutArray2
                                      .minBy(eachNumber => new Promise(resolve => {
                                          resolve(eachNumber % 10)
                                      }))
                                      .yield()
    console.log(smallest1sDigitNumberOfArray2)
    // ↑ 32

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

minByOrNull

  • minByOrNull(selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element yielding the samllest value of the given function or null if there are no elements.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const smallestNumberOfArray = await koconutArray
                              .minByOrNull(eachNumber => eachNumber)
                              .yield()
    console.log(smallestNumberOfArray)
    // ↑ 1
    
    const smallestNumberOfEmptyArray = await koconutArray
                          .filter(eachNumber => eachNumber > 10)
                          .minByOrNull(eachNumber => eachNumber)
                          .yield()
    console.log(smallestNumberOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringOfSet = await koconutSet
                              .minByOrNull(eachString => eachString.length)
                              .yield()
    console.log(shortestStringOfSet)
    // ↑ a
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1, 12, 123)
                  .associateWith(eachNumber => eachNumber.toString())
    
    const shortestDigitsEntryOfMap = await koconutMap
                                      .minByOrNull(eachEntry => eachEntry.value.length)
                                      .yield()
    console.log(shortestDigitsEntryOfMap)
    // ↑ Entry { keyElement: 1, valueElement: '1' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(19,27,32)
    
    const samllestNumberOfArray2 = await koconutArray2
                                  .minByOrNull(async eachNumber => eachNumber)
                                  .yield()
    console.log(samllestNumberOfArray2)
    // ↑ 19
    
    const smallest1sDigitNumberOfArray2 = await koconutArray2
                                      .minByOrNull(eachNumber => new Promise(resolve => {
                                          resolve(eachNumber % 10)
                                      }))
                                      .yield()
    console.log(smallest1sDigitNumberOfArray2)
    // ↑ 32

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

minOf

  • minOf(selector: (element: DataType) => number | Promise<number>, thisArg: any): KoconutPrimitive<number>
  • minOf(selector: (element: DataType) => string | Promise<string>, thisArg: any): KoconutPrimitive<string>
  • minOf<ComparableType>(selector: (element: DataType) => ComparableType | Promise<ComparableType>, thisArg: any): KoconutPrimitive<ComparableType>
  • Returns the smallest value among all values produced by selector function applied to each element in the collection or throws KoconutNoSuchElementException if there are no elements.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,7,9)
    
    const smallestRemainderNumberDividedBy5OfArray = await koconutArray
                                              .minOf(eachNumber => eachNumber % 5)
                                              .yield()
    console.log(smallestRemainderNumberDividedBy5OfArray)
    // ↑ 1
    
    try {
      await koconutArray
              .filter(eachNumber => eachNumber > 10)
              .minOf(eachNumber => eachNumber % 5)
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringLengthOfSet = await koconutSet
                              .minOf(eachString => eachString.length)
                              .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ 1
    
    class ComparableString implements KoconutComparable{
      str : string
      constructor(str : string) {
          this.str = str
      }
      // Override
      compareTo(other : ComparableString) : number {
          return this.str.length - other.str.length
      }
    }
    const minComparableString = await koconutSet
                          .minOf(eachString => new ComparableString(eachString))
                          .yield()
    console.log(minComparableString)
    // ↑ ComparableString { str: 'a' }
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                  .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthOfMap = await koconutMap
                                  .minOf(eachEntry => eachEntry.key)
                                  .yield()
    console.log(shortestStringLengthOfMap)
    // ↑ 1
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                          .minOf(async eachNumber => eachNumber)
                          .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitOfArray2 = await koconutArray2
                          .minOf(eachNumber => new Promise(resolve => {
                              resolve(eachNumber % 10)
                          }))
                          .yield()
    console.log(smallest1sDigitOfArray2)
    // ↑ 0

    Parameters

    • selector: (element: DataType) => number | Promise<number>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): number | Promise<number>
        • Parameters

          • element: DataType

          Returns number | Promise<number>

    • thisArg: any

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<number>

  • Parameters

    • selector: (element: DataType) => string | Promise<string>
        • (element: DataType): string | Promise<string>
        • Parameters

          • element: DataType

          Returns string | Promise<string>

    • thisArg: any

    Returns KoconutPrimitive<string>

  • Type parameters

    Parameters

    • selector: (element: DataType) => ComparableType | Promise<ComparableType>
        • (element: DataType): ComparableType | Promise<ComparableType>
        • Parameters

          • element: DataType

          Returns ComparableType | Promise<ComparableType>

    • thisArg: any

    Returns KoconutPrimitive<ComparableType>

minOfOrNull

  • minOfOrNull(selector: (element: DataType) => number | Promise<number>, thisArg: any): KoconutPrimitive<number | null>
  • minOfOrNull(selector: (element: DataType) => string | Promise<string>, thisArg: any): KoconutPrimitive<string | null>
  • minOfOrNull<ComparableType>(selector: (element: DataType) => ComparableType | Promise<ComparableType>, thisArg: any): KoconutPrimitive<ComparableType | null>
  • Returns the smallest value among all values produced by selector function applied to each element in the collection or null if there are no elements.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,7,9)
    
    const smallestRemainderNumberDividedBy5OfArray = await koconutArray
                                              .minOfOrNull(eachNumber => eachNumber % 5)
                                              .yield()
    console.log(smallestRemainderNumberDividedBy5OfArray)
    // ↑ 1
    
    const smallestRemainderNumberDividedBy5OfEmptyArray = await koconutArray
                                          .filter(eachNumber => eachNumber > 10)
                                          .minOfOrNull(eachNumber => eachNumber % 5)
                                          .yield()
    console.log(smallestRemainderNumberDividedBy5OfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringLengthOfSet = await koconutSet
                              .minOfOrNull(eachString => eachString.length)
                              .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ 1
    
    class ComparableString implements KoconutComparable{
      str : string
      constructor(str : string) {
          this.str = str
      }
      // Override
      compareTo(other : ComparableString) : number {
          return this.str.length - other.str.length
      }
    }
    const minComparableString = await koconutSet
                          .minOfOrNull(eachString => new ComparableString(eachString))
                          .yield()
    console.log(minComparableString)
    // ↑ ComparableString { str: 'a' }
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                  .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthOfMap = await koconutMap
                                  .minOfOrNull(eachEntry => eachEntry.key)
                                  .yield()
    console.log(shortestStringLengthOfMap)
    // ↑ 1
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                          .minOfOrNull(async eachNumber => eachNumber)
                          .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitOfArray2 = await koconutArray2
                          .minOfOrNull(eachNumber => new Promise(resolve => {
                              resolve(eachNumber % 10)
                          }))
                          .yield()
    console.log(smallest1sDigitOfArray2)
    // ↑ 0

    Parameters

    • selector: (element: DataType) => number | Promise<number>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): number | Promise<number>
        • Parameters

          • element: DataType

          Returns number | Promise<number>

    • thisArg: any

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<number | null>

  • Parameters

    • selector: (element: DataType) => string | Promise<string>
        • (element: DataType): string | Promise<string>
        • Parameters

          • element: DataType

          Returns string | Promise<string>

    • thisArg: any

    Returns KoconutPrimitive<string | null>

  • Type parameters

    Parameters

    • selector: (element: DataType) => ComparableType | Promise<ComparableType>
        • (element: DataType): ComparableType | Promise<ComparableType>
        • Parameters

          • element: DataType

          Returns ComparableType | Promise<ComparableType>

    • thisArg: any

    Returns KoconutPrimitive<ComparableType | null>

minOfWith

  • minOfWith<ResultDataType>(selector: (element: DataType) => ResultDataType | Promise<ResultDataType>, comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>, selectorThisArg?: any, comparatorThisArg?: any): KoconutPrimitive<ResultDataType>
  • Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection all throws KoconutNoSuchElementException if elements are empty.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of("1", "2", "3", "4", "5")
    
    const smallestNumberedStringOfArray = await koconutArray
                                  .minOfWith(
                                      parseInt,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(smallestNumberedStringOfArray)
    // ↑ 1
    
    try {
      await koconutArray
              .filter(eachString => eachString.length > 2)
              .minOfWith(
                  parseInt,
                  (front, rear) => front - rear
              )
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No string in "1" to "5" is logner than 2.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringLengthOfSet = await koconutSet
                              .minOfWith(
                                  eachString => eachString.length,
                                  (front, rear) => front - rear
                              )
                              .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ 1
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                  .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthOfMap = await koconutMap
                                  .minOfWith(
                                      eachEntry => eachEntry.key,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(shortestStringLengthOfMap)
    // ↑ 1
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                              .minOfWith(
                                  async eachNumber => eachNumber,
                                  async (front, rear) => front - rear
                              )
                              .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitOfArray2 = await koconutArray2
                              .minOfWith(
                                  (eachNumber) => new Promise<number>(resolve => {
                                      resolve(eachNumber % 10)
                                  }),
                                  (front, rear) => new Promise(resolve => {
                                      resolve(front - rear)
                                  })
                              )
                              .yield()
    console.log(smallest1sDigitOfArray2)
    // ↑ 0

    Type parameters

    • ResultDataType

    Parameters

    • selector: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: ResultDataType, rear: ResultDataType): number | Promise<number>
        • Parameters

          • front: ResultDataType
          • rear: ResultDataType

          Returns number | Promise<number>

    • Default value selectorThisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    • Default value comparatorThisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType>

minOfWithOrNull

  • minOfWithOrNull<ResultDataType>(selector: (element: DataType) => ResultDataType | Promise<ResultDataType>, comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>, selectorThisArg?: any, comparatorThisArg?: any): KoconutPrimitive<ResultDataType | null>
  • Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection all null if elements are empty.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of("1", "2", "3", "4", "5")
    
    const smallestNumberedStringOfArray = await koconutArray
                                  .minOfWithOrNull(
                                      parseInt,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(smallestNumberedStringOfArray)
    // ↑ 1
    
    const smallestNumberedStringOfEmptyArray = await koconutArray
                              .filter(eachString => eachString.length > 2)
                              .minOfWithOrNull(
                                  parseInt,
                                  (front, rear) => front - rear
                              )
                              .yield()
    console.log(smallestNumberedStringOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc")
    
    const shortestStringLengthOfSet = await koconutSet
                              .minOfWithOrNull(
                                  eachString => eachString.length,
                                  (front, rear) => front - rear
                              )
                              .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ 1
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                  .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthOfMap = await koconutMap
                                  .minOfWithOrNull(
                                      eachEntry => eachEntry.key,
                                      (front, rear) => front - rear
                                  )
                                  .yield()
    console.log(shortestStringLengthOfMap)
    // ↑ 1
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                              .minOfWithOrNull(
                                  async eachNumber => eachNumber,
                                  async (front, rear) => front - rear
                              )
                              .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitOfArray2 = await koconutArray2
                              .minOfWithOrNull(
                                  (eachNumber) => new Promise<number>(resolve => {
                                      resolve(eachNumber % 10)
                                  }),
                                  (front, rear) => new Promise(resolve => {
                                      resolve(front - rear)
                                  })
                              )
                              .yield()
    console.log(smallest1sDigitOfArray2)
    // ↑ 0

    Type parameters

    • ResultDataType

    Parameters

    • selector: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • comparator: (front: ResultDataType, rear: ResultDataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: ResultDataType, rear: ResultDataType): number | Promise<number>
        • Parameters

          • front: ResultDataType
          • rear: ResultDataType

          Returns number | Promise<number>

    • Default value selectorThisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value.

    • Default value comparatorThisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<ResultDataType | null>

minWith

  • minWith(comparator: (front: DataType, rear: DataType) => number | Promise<number>, thisArg?: any): KoconutPrimitive<DataType>
  • Returns the first element having the smallest value according to the provided comparator or throws KoconutNoSuchElementException if elements are empty.

    throws

    KoconutNoSuchElementException

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const smallestNumberOfArray = await koconutArray
                                  .minWith((front, rear) => front - rear)
                                  .yield()
    console.log(smallestNumberOfArray)
    // ↑ 1
    
    try {
      await koconutArray
              .filter(eachNumber => eachNumber > 10)
              .minWith((front, rear) => front - rear)
              .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut No Such Element Exception
      // i.e. -- Array is filtered.
      // No element in 1 to 5 is greater than 10.
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc", "abcd")
    
    const shortestStringLengthOfSet = await koconutSet
                                      .minWith((front, rear) => front.length - rear.length)
                                      .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ a
    
    // Case 3
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                  .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthEntryOfMap = await koconutMap
                                  .minWith((front, rear) => front.key - rear.key)
                                  .yield()
    console.log(shortestStringLengthEntryOfMap)
    // ↑ Entry { keyElement: 1, valueElement: 'a' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                      .minWith(async (front, rear) => front - rear)
                      .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitNumberOfArray2 = await koconutArray2
                      .minWith((front, rear) => new Promise(resolve => {
                          resolve(front % 10 - rear % 10)
                      }))
                      .yield()
    console.log(smallest1sDigitNumberOfArray2)
    // ↑ 50

    Parameters

    • comparator: (front: DataType, rear: DataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: DataType, rear: DataType): number | Promise<number>
        • Parameters

          • front: DataType
          • rear: DataType

          Returns number | Promise<number>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

minWithOrNull

  • minWithOrNull(comparator: (front: DataType, rear: DataType) => number | Promise<number>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element having the smallest value according to the provided comparator or null if elements are empty.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const smallestNumberOfArray = await koconutArray
                                  .minWithOrNull((front, rear) => front - rear)
                                  .yield()
    console.log(smallestNumberOfArray)
    // ↑ 1
    
    const smallestNumberOfEmptyArray = await koconutArray
                              .filter(eachNumber => eachNumber > 10)
                              .minWithOrNull((front, rear) => front - rear)
                              .yield()
    console.log(smallestNumberOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("a", "ab", "abc", "abcd")
    
    const shortestStringLengthOfSet = await koconutSet
                                      .minWithOrNull((front, rear) => front.length - rear.length)
                                      .yield()
    console.log(shortestStringLengthOfSet)
    // ↑ a
    
    // Case 3
    const koconutMap = KoconutArray.of("a", "ab", "abc")
                   .associate(eachString => [eachString.length, eachString])
    
    const shortestStringLengthEntryOfMap = await koconutMap
                                  .minWithOrNull((front, rear) => front.key - rear.key)
                                  .yield()
    console.log(shortestStringLengthEntryOfMap)
    // ↑ Entry { keyElement: 1, valueElement: 'a' }
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(12,51,32,45,50)
    
    const smallestNumberOfArray2 = await koconutArray2
                      .minWithOrNull(async (front, rear) => front - rear)
                      .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 12
    
    const smallest1sDigitNumberOfArray2 = await koconutArray2
                      .minWithOrNull((front, rear) => new Promise(resolve => {
                          resolve(front % 10 - rear % 10)
                      }))
                      .yield()
    console.log(smallest1sDigitNumberOfArray2)
    // ↑ 50

    Parameters

    • comparator: (front: DataType, rear: DataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: DataType, rear: DataType): number | Promise<number>
        • Parameters

          • front: DataType
          • rear: DataType

          Returns number | Promise<number>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

Caster Methods

asArray

  • Creates an KoconutArray instance that wraps original data.

    since

    1.0.13

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const arrToArr = await koconutArray
                              .asArray()
                              .yield()
    console.log(arrToArr)
    // ↑ [ 1, 2, 3, 4, 5 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,1,2,2,3,3,4,4,5,5)
    
    const setToArr = await koconutSet
                              .asArray()
                              .yield()
    console.log(setToArr)
    // ↑ [ 1, 2, 3, 4, 5 ]
    
    // Case 3 -- KoconutFlow
    const koconutFlow = KoconutFlow.ofSimple(1,2,3,4,5)
    
    const flowToArr = await koconutFlow
                              .asArray()
                              .yield()
    console.log(flowToArr)
    // ↑
    // [
    //    Entry { keyElement: 0, valueElement: 1 },
    //    Entry { keyElement: 1, valueElement: 2 },
    //    Entry { keyElement: 2, valueElement: 3 },
    //    Entry { keyElement: 3, valueElement: 4 },
    //    Entry { keyElement: 4, valueElement: 5 }
    //  ]
    
    // Case 4 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3,4,5)
                              .associate(eachNumber => [eachNumber, eachNumber])
    
    const mapToArr = await koconutMap
                              .asArray()
                              .yield()
    console.log(mapToArr)
    // ↑
    // [
    //    Entry { keyElement: 1, valueElement: 1 },
    //    Entry { keyElement: 2, valueElement: 2 },
    //    Entry { keyElement: 3, valueElement: 3 },
    //    Entry { keyElement: 4, valueElement: 4 },
    //    Entry { keyElement: 5, valueElement: 5 }
    //  ]

    Returns KoconutArray<DataType>

asSet

  • Creates an KoconutSet instance that wraps original data.

    since

    1.0.13

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const arrToSet = await koconutArray
                              .asSet()
                              .yield()
    console.log(arrToSet)
    // ↑ Set { 1, 2, 3, 4, 5 }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,1,2,2,3,3,4,4,5,5)
    
    const setToSet = await koconutSet
                              .asSet()
                              .yield()
    console.log(setToSet)
    // ↑ Set { 1, 2, 3, 4, 5 }
    
    // Case 3 -- KoconutFlow
    const koconutFlow = KoconutFlow.ofSimple(1,2,3,4,5)
    
    const flowToSet = await koconutFlow
                              .asSet()
                              .yield()
    console.log(flowToSet)
    // ↑
    // Set {
    //    Entry { keyElement: 0, valueElement: 1 },
    //    Entry { keyElement: 1, valueElement: 2 },
    //    Entry { keyElement: 2, valueElement: 3 },
    //    Entry { keyElement: 3, valueElement: 4 },
    //    Entry { keyElement: 4, valueElement: 5 }
    //  }
    
    // Case 4 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3,4,5)
                              .associate(eachNumber => [eachNumber, eachNumber])
    
    const mapToSet = await koconutMap
                              .asSet()
                              .yield()
    console.log(mapToSet)
    // ↑
    // Set {
    //    Entry { keyElement: 1, valueElement: 1 },
    //    Entry { keyElement: 2, valueElement: 2 },
    //    Entry { keyElement: 3, valueElement: 3 },
    //    Entry { keyElement: 4, valueElement: 4 },
    //    Entry { keyElement: 5, valueElement: 5 }
    //  }

    Returns KoconutSet<DataType>

Creator Methods

Static from

  • from<DataType>(source?: Iterable<DataType> | null): KoconutSet<DataType>
  • Creates a new instance from iterable object.

    since

    1.0.11

    example
    const numbers = Array.of(1,2,3,4,5)
    const koconutNumbers = KoconutSet.from(numbers)
    // ↑ This is a Koconut number set consists of 1 to 5.
    
    const emptyNumberSet = KoconutSet.from<number>()
    // ↑ This is an empty Koconut number set.

    Type parameters

    • DataType

    Parameters

    • Default value source: Iterable<DataType> | null = null

      An array-like iterable object to convert to a KoconutSet.

    Returns KoconutSet<DataType>

Static generate

  • generate<DataType>(count: number, generator: (index: number) => DataType | Promise<DataType>, thisArg?: any): KoconutSet<DataType>
  • Creates a new instance with given count as number of values. count cannot be negative number. Each value is provided from generator with given ordered index.

    throws

    KoconutInvalidArgumentException -- When count is less than 0.

    since

    1.0.14

    example
    const evenNumberSet = await KoconutSet.generate(5, i => i*2)
                                                        .yield()
    console.log(evenNumberSet)
    // ↑ Set { 0, 2, 4, 6, 8 }

    Type parameters

    • DataType

    Parameters

    • count: number

      Number of values.

    • generator: (index: number) => DataType | Promise<DataType>

      A callback function that accepts an argument. The method calls the action one time for each ordered index.

        • (index: number): DataType | Promise<DataType>
        • Parameters

          • index: number

          Returns DataType | Promise<DataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the generator. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

Static of

  • of<DataType>(...data: DataType[]): KoconutSet<DataType>
  • Creates a new instance from variable number of arguments.

    since

    1.0.11

    example
    const koconutNumbers = KoconutSet.of(1,2,3,4,5)
    // ↑ This is a Koconut number set consists of 1 to 5.
    
    const emptyNumberSet = KoconutSet.of<number>()
    // ↑ This is an empty Koconut number set.

    Type parameters

    • DataType

    Parameters

    • Rest ...data: DataType[]

      A set of elements to include in the new KoconutSet object.

    Returns KoconutSet<DataType>

Inspector Methods

all

  • all(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutBoolean
  • Return true if all elements match te given predicate.

    since

    1.0.10

    example
      // Case 1 -- KoconutArray
      const koconutArray = KoconutArray.of(1,2,3,4,5)
    
      const areAllArrayElementsGreaterThan0 = await koconutArray
                                              .all(eachNumber => eachNumber > 0)
                                              .yield()
      console.log(areAllArrayElementsGreaterThan0)
      // ↑ true
    
      const areAllArrayElementsEven = await koconutArray
                                      .all(eachNumber => eachNumber % 2 == 0)
                                      .yield()
      console.log(areAllArrayElementsEven)
      // ↑ false -- i.e. '1' is not an even number.
    
    
      // Case 2 -- KoconutSet
      const koconutSet = KoconutSet.of(1,2,3,4,5)
    
      const areAllSetElementsGreaterThan0 = await koconutSet
                                              .all(eachNumber => eachNumber > 0)
                                              .yield()
      console.log(areAllSetElementsGreaterThan0)
      // ↑ true
    
      const areAllSetElementsOdd = await koconutSet
                                      .all(eachNumber => eachNumber % 2 == 1)
                                      .yield()
      console.log(areAllSetElementsOdd)
      // ↑ false -- i.e. '2' is not an odd number.
    
    
      // Case 3 -- KoconutMap
      const koconutMap = KoconutMap.of(
          [0, 0],
          [1, 1],
          [2, 2]
      )
    
      const areAllMapEntriesKeyEqualsToValue = await koconutMap
                                             .all(eachEntry => eachEntry.key == eachEntry.value)
                                             .yield()
      console.log(areAllMapEntriesKeyEqualsToValue)
      // ↑ true
    
      const areAllMapEntriesSumGreaterThan3 = await koconutMap
                                            .all(eachEntry => eachEntry.key + eachEntry.value > 3)
                                            .yield()
      console.log(areAllMapEntriesSumGreaterThan3)
      // ↑ false -- i.e. Sum of key and value of first Entry { 0, 0 } is 0.
      // It's definetly less than 3
    
      // Case 4 -- You can also do it asynchronously
      const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
      const areAllArrayElementsLessThan10 = await koconutArray2
                                          .all(async eachNumber => eachNumber < 10)
                                          .yield()
      console.log(areAllArrayElementsLessThan10)
      // ↑ true
    
      const areAllArrayElementsOdd = await koconutArray2
                                      .all(eachNumber => new Promise(resolve => {
                                          resolve(eachNumber % 2 == 1)
                                      }))
                                      .yield()
      console.log(areAllArrayElementsOdd)
      // ↑ false -- i.e. '2' is not an odd number.

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutBoolean

any

  • any(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutBoolean
  • Returns true if the collection has at least one element matches the given predicate.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const isAnyArrayElementGreaterThan4 = await koconutArray
                                              .any(eachNumber => eachNumber > 4)
                                              .yield()
    console.log(isAnyArrayElementGreaterThan4)
    // ↑ true -- i.e. '5' is greater than 4.
    
    const isAnyArrayElementMultipleOf6 = await koconutArray
                                              .any(eachNumber => eachNumber % 6 == 0)
                                              .yield()
    console.log(isAnyArrayElementMultipleOf6)
    // ↑ false
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const isAnySetElementGreaterThan3 = await koconutSet
                                              .any(eachNumber => eachNumber > 3)
                                              .yield()
    console.log(isAnySetElementGreaterThan3)
    // ↑ true -- i.e. '4' is greater than 3.
    
    const isAnySetElementLessThan0 = await koconutSet
                                          .any(eachNumber => eachNumber < 0)
                                          .yield()
    console.log(isAnySetElementLessThan0)
    // ↑ false
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutMap.of(
      [0, 0],
      [1, 1],
      [2, 2]
    )
    
    const isAnyMapEntrySumGreaterThan3 = await koconutMap
                                           .any(eachEntry => eachEntry.key + eachEntry.value > 3)
                                           .yield()
    console.log(isAnyMapEntrySumGreaterThan3)
    // ↑ true -- i.e. Sum of key and value of third Entry { 2, 2 } is 4.
    // It's grater than 4.
    
    const isAnyMapEntryKeyMultipleOf4 = await koconutMap
                                     .any(eachEntry => eachEntry.key > 0 && eachEntry.key % 4 == 0)
                                     .yield()
    console.log(isAnyMapEntryKeyMultipleOf4)
    // ↑ false
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const isAnyArrayElementLessThan2 = await koconutArray2
                                      .any(async eachNumber => eachNumber < 2)
                                      .yield()
    console.log(isAnyArrayElementLessThan2)
    // ↑ true -- i.e. '1' is less than 2.
    
    const isAnyArrayElementGreaterThan7 = await koconutArray2
                                          .any(eachNumber => new Promise(resolve => {
                                              resolve(eachNumber > 7)
                                          }))
                                          .yield()
    console.log(isAnyArrayElementGreaterThan7)
    // ↑ false

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutBoolean

contains

  • Checks if the specified element is contained in this collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doesArrayContain3 = await koconutArray
                                  .contains(3)
                                  .yield()
    console.log(doesArrayContain3)
    // ↑ true
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doesSetContains6 = await koconutSet
                                  .contains(6)
                                  .yield()
    console.log(doesSetContains6)
    // ↑ false

    Parameters

    • element: DataType

      The element to search for.

    Returns KoconutBoolean

containsAll

  • Checks if all the elements are contained in this collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doesArrayContain1to3 = await koconutArray
                                  .containsAll([1,2,3])
                                  .yield()
    console.log(doesArrayContain1to3)
    // ↑ true
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doesSetContains5to6 = await koconutSet
                                  .containsAll([5,6,7])
                                  .yield()
    console.log(doesSetContains5to6)
    // ↑ false

    Parameters

    • elements: Iterable<DataType>

      The elements to search for.

    Returns KoconutBoolean

isEmpty

  • Returns true if the collection is empty (contains no elements), false otherwise.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const isNumberArrayEmpty = await koconutArray
                              .isEmpty()
                              .yield()
    console.log(isNumberArrayEmpty)
    // ↑ false
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const isFilteredNumberSetEmpty = await koconutSet
                              .filter(eachNumber => eachNumber > 10)
                              .isEmpty()
                              .yield()
    console.log(isFilteredNumberSetEmpty)
    // ↑ true
    
    // Case 3 -- KoconutMap
    const koconutMap = new KoconutMap<number, number>()
    
    const isNumberPairedMapEmpty = await koconutMap
                                      .isEmpty()
                                      .yield()
    console.log(isNumberPairedMapEmpty)
    // ↑ true

    Returns KoconutBoolean

isNotEmpty

  • Returns true if the collection is not empty.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const isNumberArrayEmpty = await koconutArray
                              .isNotEmpty()
                              .yield()
    console.log(isNumberArrayEmpty)
    // ↑ true
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const isFilteredNumberSetEmpty = await koconutSet
                              .filter(eachNumber => eachNumber > 10)
                              .isNotEmpty()
                              .yield()
    console.log(isFilteredNumberSetEmpty)
    // ↑ false
    
    // Case 3 -- KoconutMap
    const koconutMap = new KoconutMap<number, number>()
    
    const isNumberPairedMapEmpty = await koconutMap
                                      .isNotEmpty()
                                      .yield()
    console.log(isNumberPairedMapEmpty)
    // ↑ false

    Returns KoconutBoolean

isNullOrEmpty

  • Returns true if this nullable collection is either null or empty.

    since

    1.0.10

    deprecated

    Use isEmpty instead.

    until

    1.3.0

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const isNumberArrayEmpty = await koconutArray
                              .isNullOrEmpty()
                              .yield()
    console.log(isNumberArrayEmpty)
    // ↑ false
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const isFilteredNumberSetEmpty = await koconutSet
                              .filter(eachNumber => eachNumber > 10)
                              .isNullOrEmpty()
                              .yield()
    console.log(isFilteredNumberSetEmpty)
    // ↑ true
    
    // Case 3 -- KoconutMap
    const koconutMap = new KoconutMap<number, number>()
    
    const isNumberPairedMapEmpty = await koconutMap
                                      .isNullOrEmpty()
                                      .yield()
    console.log(isNumberPairedMapEmpty)
    // ↑ true

    Returns KoconutBoolean

none

  • none(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutBoolean
  • predicate callback function is optional. If it's omitted the method returns true if the collection has no elements. Otherwise, returns true if no elements match the given predicate.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = new KoconutArray<number>()
    
    const isNoneOfAnEmptyArray = await koconutArray
                                      .none()
                                      .yield()
    console.log(isNoneOfAnEmptyArray)
    // ↑ true
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const isNoneOfSetElementGreaterThan10 = await koconutSet
                                          .none(eachNumber => eachNumber >= 10)
                                          .yield()
    console.log(isNoneOfSetElementGreaterThan10)
    // ↑ true
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3,4,5)
                      .associateWith(eachNumber => eachNumber * 2)
    
    const isNoneOfEntryOfMapHasLessThan3DifferenceBetweenKeyAndValue
                          = await koconutMap
                              .none(eachEntry => eachEntry.value - eachEntry.key <= 3)
                              .yield()
    console.log(isNoneOfEntryOfMapHasLessThan3DifferenceBetweenKeyAndValue)
    // ↑ false
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const isNoneOfArrayElementGreaterThan3 = await koconutArray2
                                      .none(async eachNumber => eachNumber >= 3)
                                      .yield()
    console.log(isNoneOfArrayElementGreaterThan3)
    // ↑ false
    
    const isNoneOfArrayelementLessThan0 = await koconutArray2
                      .none(eachNumber => new Promise(resolve => {
                          resolve(eachNumber <= 0)
                      }))
                      .yield()
    console.log(isNoneOfArrayelementLessThan0)
    // ↑ true

    Parameters

    • Default value predicate: ((element: DataType) => boolean | Promise<boolean>) | null = null

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutBoolean

Iterator Methods

forEach

  • Performs the given action on each element. When you want to stop iteration in the meantime return false or KoconutLoopSignal.BREAK.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5,6,7)
    await koconutArray
      .forEach(console.log)
      // ↑ 1 2 3 4 5 6 7  -- i.e. This will print out each number
      .process()
    
    await koconutArray
      .forEach(eachNumber => {
          if(eachNumber > 4) return KoconutLoopSignal.BREAK
          console.log(eachNumber)
      })
      // ↑ 1 2 3 4  -- i.e. Since '5', it is greater than 4, so the loop is broken.
      .process()
    
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,1,2,3)
    
    await koconutSet
      .forEach(console.log)
      // ↑ 1 2 3 -- i.e. All conflicted numbers will be ignored.
      .process()
    
    await koconutSet
      .forEach(eachNumber => {
          if(eachNumber % 2 == 0) return false
          console.log(eachNumber)
      })
      // ↑ 1 -- i.e. Since '2', it is an even number, so the loop is broken.
      .process()
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3)
                      .associateWith(eachElement => eachElement)
    
    await koconutMap
      .forEach(console.log)
      // ↑
      // Entry { keyElement: 1, valueElement: 1 }
      // Entry { keyElement: 2, valueElement: 2 }
      // Entry { keyElement: 3, valueElement: 3 }
      .process()
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3)
    
    await koconutArray2
      .forEach(async eachNumber => console.log(eachNumber))
      // ↑ 1 2 3
      .process()
    
    await koconutArray2
      .forEach(eachNumber => new Promise(resolve => resolve(console.log(eachNumber))))
      // ↑ 1 2 3
      .process()

    Parameters

    • action: (element: DataType) => boolean | KoconutLoopSignal | void | Promise<boolean | KoconutLoopSignal | void>

      A callback function that accepts an argument. The method calls the action one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the action. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<void>

forEachIndexed

  • forEachIndexed(action: (index: number, element: DataType) => boolean | KoconutLoopSignal | void | Promise<boolean | KoconutLoopSignal | void>, thisArg?: any): KoconutPrimitive<void>
  • Performs the given action on each element, providing sequential index with the element. When you want to stop iteration in the meantime return false or KoconutLoopSignal.BREAK.

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5,6,7)
    
    await koconutArray
          .forEachIndexed(console.log)
          // ↑ 0 1
          //   1 2
          //   2 3
          //   3 4
          //   4 5
          //   5 6
          //   6 7
          .process()
    
    await koconutArray
          .forEachIndexed((eachIndex, eachNumber) => {
              if(eachIndex == 3) return KoconutLoopSignal.BREAK
              console.log(eachNumber)
          })
          // ↑ 1 2 3 -- i.e. Since when the index is '3', the loop is interrupted.
          // The last printed number(element) would be '3'.
          .process()
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,1,2,3)
    
    await koconutSet
          .forEachIndexed(console.log)
          // ↑ 0 1
          //   1 2
          //   2 3
          .process()
    
    await koconutSet
          .forEachIndexed((eachIndex, eachNumber) => {
              if(eachIndex != 0 && eachIndex % 2 == 0) return false
              console.log(eachNumber)
          })
          // ↑ 1 2 -- i.e. Since when the index '2', it's an even number.
          // So the loop is interrupted.
          // The last printed number(element) would be '2'
          .process()
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3)
    
    await koconutArray2
          .forEachIndexed(async (eachIndex, eachNumber) =>
                          console.log(eachIndex, eachNumber))
          // ↑ 0 1
          //   1 2
          //   2 3
          .process()
    
    await koconutArray2
          .forEachIndexed(async (eachIndex, eachNumber) => new Promise(resolve => {
              resolve(console.log(eachIndex, eachNumber))
          }))
          // ↑ 0 1
          //   1 2
          //   2 3
          .process()

    Parameters

    • action: (index: number, element: DataType) => boolean | KoconutLoopSignal | void | Promise<boolean | KoconutLoopSignal | void>

      A callback function that accepts two arguments. The method calls the action one time for each index and element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the action. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<void>

onEach

  • Perfroms the given action on each element and returns the original collection itself afterwards. When you want to stop iteration in the meantime return false or KoconutLoopSignal.BREAK.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const set = await koconutSet
                      .onEach(console.log)
                      // ↑ 1
                      //   2
                      //   3
                      //   4
                      //   5
                      .onEach(async eachNumber => {
                          if(eachNumber >= 3) return KoconutLoopSignal.BREAK
                          console.log(eachNumber)
                      })
                      // ↑ 1
                      //   2
                      .onEach(eachNumber => new Promise(resolve => {
                          if(eachNumber == 2) resolve(false)
                          else {
                              console.log(eachNumber)
                              resolve()
                          }
                      }))
                      // ↑ 1
                      .yield()
    console.log(set)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Parameters

    • action: (element: DataType) => boolean | KoconutLoopSignal | void | Promise<boolean | KoconutLoopSignal | void>

      A callback function that accepts an argument. The method calls the action one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the action. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

onEachIndexed

  • Performs the given action on each element, providing sequential index with the element, and returns the collection itself afterwards. When you want to stop iteration in the meantime return false or KoconutLoopSignal.BREAK.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const set = await koconutSet
                    .onEachIndexed(console.log)
                    // ↑ 0 1
                    //   1 2
                    //   2 3
                    //   3 4
                    //   4 5
                    .onEachIndexed(async (eachIndex, eachNumber) => {
                        if(eachIndex >= 2) return KoconutLoopSignal.BREAK
                        console.log(eachNumber)
                    })
                    // ↑ 1
                    //   2
                    .onEachIndexed((eachIndex, eachNumber) => new Promise(resolve => {
                        if(eachIndex == 2) resolve(false)
                        else {
                            console.log(eachNumber)
                            resolve()
                        }
                    }))
                    // ↑ 1
                    //   2
                    .yield()
    console.log(set)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Parameters

    • action: (index: number, element: DataType) => boolean | KoconutLoopSignal | void | Promise<boolean | KoconutLoopSignal | void>

      A callback function that accepts two arguments. The method calls the action one time for each index and element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the action. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

Manipulator Methods

distinct

  • Returns a KoconutSet containing only distinct elements from this collection. If the type of data is a simple number or string, the method will check equality by using '==' operator, but if it's not, you'd better make your custom class inherits KoconutEquatable.

    since

    1.0.10

    example
    const numberKoconutSet = KoconutSet.of(1,1,2,2,3,3)
    
    const distinctNumbers = await numberKoconutSet
                                  .distinct()
                                  .yield()
    console.log(distinctNumbers)
    // ↑ Set { 1, 2, 3 }
    
    class SomeInfo {
      info : string
      constructor(info : string) {
          this.info = info
      }
    }
    const someInfoKoconutSet = KoconutSet.of(
      new SomeInfo("A"),
      new SomeInfo("A"),
      new SomeInfo("B"),
      new SomeInfo("B"),
      new SomeInfo("C"),
      new SomeInfo("C"),
    )
    const distinctSomeInfos = await someInfoKoconutSet
                              .distinct()
                              .yield()
    console.log(distinctSomeInfos)
    // ↑ Set {
    //        SomeInfo { info: 'A' },
    //        SomeInfo { info: 'A' },
    //        SomeInfo { info: 'B' },
    //        SomeInfo { info: 'B' },
    //        SomeInfo { info: 'C' },
    //        SomeInfo { info: 'C' }
    //       }
    
    class SomeEquatableInfo implements KoconutEquatable {
      info : string
      constructor(info : string) {
          this.info = info
      }
      equalsTo(other : SomeEquatableInfo) : boolean {
          return this.info == other.info
      }
    }
    const someEquatableInfoKoconutSet = KoconutSet.of(
      new SomeEquatableInfo("A"),
      new SomeEquatableInfo("A"),
      new SomeEquatableInfo("B"),
      new SomeEquatableInfo("B"),
      new SomeEquatableInfo("C"),
      new SomeEquatableInfo("C")
    )
    const distinctSomeEquatableInfos = await someEquatableInfoKoconutSet
                                      .distinct()
                                      .yield()
    console.log(distinctSomeEquatableInfos)
    // ↑ Set {
    //        SomeEquatableInfo { info: 'A' },
    //        SomeEquatableInfo { info: 'B' },
    //        SomeEquatableInfo { info: 'C' }
    //       }

    Returns KoconutSet<DataType>

distinctBy

  • distinctBy<KeyType, EuqatableKeyType>(selector: (element: DataType) => KeyType | EuqatableKeyType | Promise<KeyType>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing only elements from the given collection having distinct keys returned by the given selector function.

    since

    1.0.10

    example
    const numberKoconutSet = KoconutSet.of(1,1,2,2,3,3)
    
    const distinctNumbers = await numberKoconutSet
                            .distinctBy(eachNumber => eachNumber)
                            .yield()
    console.log(distinctNumbers)
    // ↑ Set { 1, 2, 3 }
    
    class SomeInfo {
        info : string
        constructor(info : string) {
            this.info = info
        }
    }
    const someInfoKoconutSet = KoconutSet.of(
        new SomeInfo("A"),
        new SomeInfo("A"),
        new SomeInfo("B"),
        new SomeInfo("B"),
        new SomeInfo("C"),
        new SomeInfo("C")
    )
    const distinctSomeInfos = await someInfoKoconutSet
                        .distinctBy(eachSomeInfo => eachSomeInfo.info)
                        .yield()
    console.log(distinctSomeInfos)
    // ↑ Set {
    //        SomeInfo { info: 'A' },
    //        SomeInfo { info: 'B' },
    //        SomeInfo { info: 'C' }
    //       }
    
    class SomeEquatableInfo implements KoconutEquatable {
        info : string
        constructor(info : string) {
            this.info = info
        }
        equalsTo(other : SomeEquatableInfo) : boolean {
            return this.info == other.info
        }
    }
    class SomeEquatableInfoContainer {
        someEquatableInfo : SomeEquatableInfo
        additionalInfo : string
        constructor(someEquatableInfo : SomeEquatableInfo, additionalInfo : string) {
            this.someEquatableInfo = someEquatableInfo
            this.additionalInfo = additionalInfo
        }
    }
    const someEquatableInfoContainerKoconutSet = KoconutSet.of(
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("A"),
            "First"
        ),
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("A"),
            "Second"
        ),
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("B"),
            "First"
        ),
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("B"),
            "Second"
        ),
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("C"),
            "First"
        ),
        new SomeEquatableInfoContainer(
            new SomeEquatableInfo("C"),
            "Second"
        )
    )
    const distinctSomeEquatableInfoContainersByEquatableInfo =
                    await someEquatableInfoContainerKoconutSet
                    .distinctBy(async eachContainer => eachContainer.someEquatableInfo)
                    .yield()
    console.log(distinctSomeEquatableInfoContainersByEquatableInfo)
    // ↑ Set {
    //            SomeEquatableInfoContainer {
    //                someEquatableInfo: SomeEquatableInfo { info: 'A' },
    //                additionalInfo: 'First'
    //            },
    //            SomeEquatableInfoContainer {
    //                someEquatableInfo: SomeEquatableInfo { info: 'B' },
    //                additionalInfo: 'First'
    //            },
    //            SomeEquatableInfoContainer {
    //                someEquatableInfo: SomeEquatableInfo { info: 'C' },
    //                additionalInfo: 'First'
    //            }
    //       }
    
    const distinctSomeEquatableInfoContainersByAdditionalInfo =
                    await someEquatableInfoContainerKoconutSet
                    .distinctBy(eachContainer => new Promise(resolve => {
                        resolve(eachContainer.additionalInfo)
                    }))
                    .yield()
    console.log(distinctSomeEquatableInfoContainersByAdditionalInfo)
    // ↑ Set {
    //            SomeEquatableInfoContainer {
    //                someEquatableInfo: SomeEquatableInfo { info: 'A' },
    //                additionalInfo: 'First'
    //            },
    //            SomeEquatableInfoContainer {
    //                someEquatableInfo: SomeEquatableInfo { info: 'A' },
    //                additionalInfo: 'Second'
    //            }
    //       }

    Type parameters

    Parameters

    • selector: (element: DataType) => KeyType | EuqatableKeyType | Promise<KeyType>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

        • (element: DataType): KeyType | EuqatableKeyType | Promise<KeyType>
        • Parameters

          • element: DataType

          Returns KeyType | EuqatableKeyType | Promise<KeyType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value

    Returns KoconutSet<DataType>

drop

  • Returns a KoconutSet containing all elements except first n elements.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const fisrt3ElementsDroppedSet = await koconutSet
                                            .drop(3)
                                            .yield()
    console.log(fisrt3ElementsDroppedSet)
    // ↑ Set { 4, 5 }

    Parameters

    • n: number

      Elements number to except.

    Returns KoconutSet<DataType>

dropLast

  • Returns a KoconutSet containg all elements except last n elements.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const last3ElementsDroppedSet = await koconutSet
                                            .dropLast(3)
                                            .yield()
    console.log(last3ElementsDroppedSet)
    // ↑ Set  { 1, 2 }

    Parameters

    • n: number

      Elements number to except.

    Returns KoconutSet<DataType>

dropLastWhile

  • dropLastWhile(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing all elements except last elements that satisfy the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const greaterThan5DroppedSet = await koconutSet
                    .dropLastWhile(eachNumber => eachNumber > 5)
                    .yield()
    console.log(greaterThan5DroppedSet)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

dropWhile

  • dropWhile(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing all elements except first elements that satisfy the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const lessThan5DroppedSet = await koconutSet
                    .dropWhile(eachNumber => eachNumber < 5)
                    .yield()
    console.log(lessThan5DroppedSet)
    // ↑ Set { 5, 6, 7, 8, 9, 10 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filter

  • filter(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing only elements matching the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const evenNumbers = await koconutSet
                          .filter(eachNumber => eachNumber % 2 == 0)
                          .yield()
    console.log(evenNumbers)
    // ↑ Set { 2, 4 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filterIndexed

  • filterIndexed(predicate: (index: number, element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing only elements matching the given predicate with indexes.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(0,1,2,5,6,7)
    
    const numbersEqualToIndex = await koconutSet
          .filterIndexed((eachIndex, eachNumber) => eachIndex == eachNumber)
          .yield()
    console.log(numbersEqualToIndex)
    // ↑ Set { 0, 1, 2 }

    Parameters

    • predicate: (index: number, element: DataType) => boolean | Promise<boolean>

      A callback function that accepts two arguments. The method calls the predicate one time for each index and element in object.

        • (index: number, element: DataType): boolean | Promise<boolean>
        • Parameters

          • index: number
          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filterIndexedTo

  • filterIndexedTo(destination: Array<DataType> | Set<DataType>, predicate: (index: number, element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Appends all elements matching the given predicate with indexes to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(0,1,2,5,6,7)
    
    const numbersEqualToIndex = new Array<number>()
    const origianlData =await koconutSet
          .filterIndexedTo(
              numbersEqualToIndex,
              (eachIndex, eachNumber) => eachIndex == eachNumber
          )
          .yield()
    console.log(numbersEqualToIndex)
    // ↑ [ 0, 1, 2 ]
    console.log(origianlData)
    // ↑ Set { 0, 1, 2, 5, 6, 7 }

    Parameters

    • destination: Array<DataType> | Set<DataType>

      Iterable destinaion. Array or Set to be exact.

    • predicate: (index: number, element: DataType) => boolean | Promise<boolean>

      A callback function that accepts two arguments. The method calls the predicate one time for each index and element in object.

        • (index: number, element: DataType): boolean | Promise<boolean>
        • Parameters

          • index: number
          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filterNot

  • filterNot(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing only elements not matching the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const oddNumbers = await koconutSet
                          .filterNot(eachNumber => eachNumber % 2 == 0)
                          .yield()
    console.log(oddNumbers)
    // ↑ Set { 1, 3, 5 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filterNotNull

  • Returns a KoconutSet containing all elements that are not null.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,null,null)
    
    const numbers = await koconutSet
                  .filterNotNull()
                  .yield()
    console.log(numbers)
    // ↑ Set { 1, 2 }

    Returns KoconutSet<DataType>

filterNotNullTo

  • filterNotNullTo(destination: Array<DataType> | Set<DataType>): KoconutSet<DataType>
  • Appends all elements that are not null to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,null,null)
    
    const numbers = Array<number>()
    const originalData = await koconutSet
                      .filterNotNullTo(numbers)
                      .yield()
    console.log(numbers)
    // ↑ [ 1, 2 ]
    console.log(originalData)
    // ↑ Set { 1, 2, null }

    Parameters

    • destination: Array<DataType> | Set<DataType>

    Returns KoconutSet<DataType>

filterNotTo

  • filterNotTo(destination: Array<DataType> | Set<DataType>, predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Appends all elements not matching the given predicate to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const oddNumbers = new Array<number>()
    const originalData = await koconutSet
                          .filterTo(
                              oddNumbers,
                              eachNumber => eachNumber % 2 == 0
                          )
                          .yield()
    console.log(oddNumbers)
    // ↑ [ 1, 3, 5 ]
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Parameters

    • destination: Array<DataType> | Set<DataType>

      Iterable destinaion. Array or Set to be exact.

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

filterTo

  • filterTo(destination: Array<DataType> | Set<DataType>, predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Appends all elements matching the given predicate to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const evenNumbers = new Array<number>()
    const originalData = await koconutSet
                          .filterTo(
                              evenNumbers,
                              eachNumber => eachNumber % 2 == 0
                          )
                          .yield()
    console.log(evenNumbers)
    // ↑ [ 2, 4 ]
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Parameters

    • destination: Array<DataType> | Set<DataType>

      Iterable destinaion. Array or Set to be exact.

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

sortedBy

  • Returns a KoconutSet of all elements sorted according to natural sort order of the value returned by specified selector function. It could be either a number, string, or custom class that inherits KoconutComparable.

    since

    1.0.10

    example
    const stringKoconutSet = KoconutSet.of("abcd", "ab", "a", "abc")
    
    const sortedStringByItsLength = await stringKoconutSet
                                      .sortedBy(eachString => eachString.length)
                                      .yield()
    console.log(sortedStringByItsLength)
    // ↑ Set { 'a', 'ab', 'abc', 'abcd' }
    
    class Person implements KoconutComparable {
      name : string
      age : number
      constructor(name : string, age : number) {
          this.name = name
          this.age = age
      }
      compareTo(other : Person) : number {
          return this.name.length - other.name.length
      }
    }
    const personKoconutSet = KoconutSet.of(
      new Person("Keanu Reeves", 56),
      new Person("Robert Downey Jr.", 55),
      new Person("Christian Bale", 46)
    )
    
    // You can do it by async function.
    const sortedPeopleByWhoseAge = await personKoconutSet
                                      .sortedBy(async eachPerson => eachPerson.age)
                                      .yield()
    console.log(sortedPeopleByWhoseAge)
    // ↑ Set {
    //        Person { name: 'Christian Bale', age: 46 },
    //        Person { name: 'Robert Downey Jr.', age: 55 },
    //        Person { name: 'Keanu Reeves', age: 56 }
    //       }
    
    // And of course, by returning Promise.
    const sortedPeopleByWhoseName = await personKoconutSet
                                      .sortedBy(eachPerson => new Promise(resolve => {
                                          resolve(eachPerson.name)
                                      }))
                                      .yield()
    console.log(sortedPeopleByWhoseName)
    // ↑ Set {
    //        Person { name: 'Christian Bale', age: 46 },
    //        Person { name: 'Keanu Reeves', age: 56 },
    //        Person { name: 'Robert Downey Jr.', age: 55 }
    //       }
    
    // The class Person itself implements KoconutComparable.
    // So, it is a Comparable Type.
    // If you're using JavaScript you can do something similar as following
    // by extending KoconutComparable or simply adding method 'compareTo' to your custom class.
    const sortedPeople = await personKoconutSet
                              .sortedBy(eachPerson => eachPerson)
                              .yield()
    console.log(sortedPeople)
    // ↑ Set {
    //        Person { name: 'Keanu Reeves', age: 56 },
    //        Person { name: 'Christian Bale', age: 46 },
    //        Person { name: 'Robert Downey Jr.', age: 55 }
    //       }

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value

    Returns KoconutSet<DataType>

sortedByDescending

  • Returns a KoconutSet of all elements sorted descending according to natural sort order of the value returned by specified selector function. It could be either a number, string, or custom class that inherits KoconutComparable.

    since

    1.0.10

    example
    const stringKoconutSet = KoconutSet.of("abcd", "ab", "a", "abc")
    
    const descSortedStringByItsLength = await stringKoconutSet
                                      .sortedByDescending(eachString => eachString.length)
                                      .yield()
    console.log(descSortedStringByItsLength)
    // ↑ Set { 'abcd', 'abc', 'ab', 'a' }
    
    class Person implements KoconutComparable {
      name : string
      age : number
      constructor(name : string, age : number) {
          this.name = name
          this.age = age
      }
      compareTo(other : Person) : number {
          return this.name.length - other.name.length
      }
    }
    const personKoconutSet = KoconutSet.of(
      new Person("Keanu Reeves", 56),
      new Person("Robert Downey Jr.", 55),
      new Person("Christian Bale", 46)
    )
    
    // You can do it by async function.
    const descSortedPeopleByWhoseAge = await personKoconutSet
                                      .sortedByDescending(async eachPerson => eachPerson.age)
                                      .yield()
    console.log(descSortedPeopleByWhoseAge)
    // ↑ Set {
    //        Person { name: 'Keanu Reeves', age: 56 },
    //        Person { name: 'Robert Downey Jr.', age: 55 },
    //        Person { name: 'Christian Bale', age: 46 }
    //       }
    
    // And of course, by returning Promise.
    const descSortedPeopleByWhoseName = await personKoconutSet
                                      .sortedByDescending(eachPerson => new Promise(resolve => {
                                          resolve(eachPerson.name)
                                      }))
                                      .yield()
    console.log(descSortedPeopleByWhoseName)
    // ↑ Set {
    //        Person { name: 'Robert Downey Jr.', age: 55 },
    //        Person { name: 'Keanu Reeves', age: 56 },
    //        Person { name: 'Christian Bale', age: 46 }
    //       }
    
    // The class Person itself implements KoconutComparable.
    // So, it is a Comparable Type.
    // If you're using JavaScript you can do something similar as following
    // by extending KoconutComparable or simply adding method 'compareTo' to your custom class.
    const descSortedPeople = await personKoconutSet
                              .sortedByDescending(eachPerson => eachPerson)
                              .yield()
    console.log(descSortedPeople)
    // ↑ Set {
    //        Person { name: 'Robert Downey Jr.', age: 55 },
    //        Person { name: 'Christian Bale', age: 46 },
    //        Person { name: 'Keanu Reeves', age: 56 }
    //       }

    Parameters

    • selector: (element: DataType) => number | string | KoconutComparable | Promise<number | string | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the selector. If thisArg is omitted, null is used as the this value

    Returns KoconutSet<DataType>

sortedWith

  • sortedWith(comparator: (front: DataType, rear: DataType) => number | Promise<number>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet of all elements sorted according to the specified comparator.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(15, 4, 33)
    
    const sortedNumbers = await koconutSet
                          .sortedWith((front, rear) => front - rear)
                          .yield()
    console.log(sortedNumbers)
    // ↑ Set { 4, 15, 33 }
    
    const descSortedNumbers = await koconutSet
                              .sortedWith((front, rear) => rear - front)
                              .yield()
    console.log(descSortedNumbers)
    // ↑ Set { 4, 15, 33 }
    
    const sortedNumbersBy1sDigit = await koconutSet
                          .sortedWith((front, rear) => front % 10 - rear % 10)
                          .yield()
    console.log(sortedNumbersBy1sDigit)
    // ↑ Set { 4, 15, 33 }

    Parameters

    • comparator: (front: DataType, rear: DataType) => number | Promise<number>

      A callback function that accepts two arguements. The method calls the comparator to compare two selected values. In case the result is larger than 0, front is bigger than rear, and if it's less than 0 judge vice versa.

        • (front: DataType, rear: DataType): number | Promise<number>
        • Parameters

          • front: DataType
          • rear: DataType

          Returns number | Promise<number>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the comparator. If thisArg is omitted, null is used as the this value

    Returns KoconutSet<DataType>

take

  • Returns a KoconutSet containing first n elements.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const first3ElementsOfSet = await koconutSet
                                    .take(3)
                                    .yield()
    console.log(first3ElementsOfSet)
    // ↑ Set { 1, 2, 3 }

    Parameters

    • n: number

      Elements number to take.

    Returns KoconutSet<DataType>

takeLast

  • Returns a KoconutSet containg last n elements.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const last3ElementsOfSet = await koconutSet
                                    .takeLast(3)
                                    .yield()
    console.log(last3ElementsOfSet)
    // ↑ Set { 8, 9, 10 }

    Parameters

    • n: number

      Elements number to take.

    Returns KoconutSet<DataType>

takeLastWhile

  • takeLastWhile(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing last elements satisfying the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const lastNumbersWhileGreaterThan7 = await koconutSet
                        .takeLastWhile(eachNumber => eachNumber >7)
                        .yield()
    console.log(lastNumbersWhileGreaterThan7)
    // ↑ Set { 8, 9, 10 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

takeWhile

  • takeWhile(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutSet<DataType>
  • Returns a KoconutSet containing first elements satisfying the given predicate.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(
        1,2,3,4,5,6,7,8,9,10
    )
    
    const numbersWhileLessThan5 = await koconutSet
                        .takeWhile(eachNumber => eachNumber < 5)
                        .yield()
    console.log(numbersWhileLessThan5)
    // ↑ Set { 1, 2, 3, 4 }

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

Other Methods

groupBy

  • groupBy<KeyType, ValueType>(keySelector: (element: DataType) => KeyType | Promise<KeyType>, valueTransform?: ((element: DataType) => ValueType | Promise<ValueType>) | null, keySelectorThisArg?: any, valueTransformThisArg?: any): KoconutMap<KeyType, Array<ValueType>>
  • Type parameters

    • KeyType

    • ValueType = DataType

    Parameters

    • keySelector: (element: DataType) => KeyType | Promise<KeyType>
        • (element: DataType): KeyType | Promise<KeyType>
        • Parameters

          • element: DataType

          Returns KeyType | Promise<KeyType>

    • Default value valueTransform: ((element: DataType) => ValueType | Promise<ValueType>) | null = null
    • Default value keySelectorThisArg: any = null
    • Default value valueTransformThisArg: any = null

    Returns KoconutMap<KeyType, Array<ValueType>>

groupByTo

  • groupByTo<KeyType, ValueType>(destination: Map<KeyType, Array<ValueType>>, keySelector: (element: DataType) => KeyType | Promise<KeyType>, valueTransform?: ((element: DataType) => ValueType | Promise<ValueType>) | null, keySelectorThisArg?: any, valueTransformThisArg?: any): KoconutSet<DataType>
  • Type parameters

    • KeyType

    • ValueType = DataType

    Parameters

    • destination: Map<KeyType, Array<ValueType>>
    • keySelector: (element: DataType) => KeyType | Promise<KeyType>
        • (element: DataType): KeyType | Promise<KeyType>
        • Parameters

          • element: DataType

          Returns KeyType | Promise<KeyType>

    • Default value valueTransform: ((element: DataType) => ValueType | Promise<ValueType>) | null = null
    • Default value keySelectorThisArg: any = null
    • Default value valueTransformThisArg: any = null

    Returns KoconutSet<DataType>

indexOf

  • indexOf(elementToFind: DataType): KoconutPrimitive<number>

indexOfFirst

  • indexOfFirst(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutPrimitive<number>

indexOfLast

  • indexOfLast(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutPrimitive<number>

indices

intersect

  • intersect(other: Iterable<DataType>): KoconutSet<DataType>

join

  • join(separator?: string, prefix?: string, postfix?: string, limit?: number, truncated?: string, transform?: ((element: DataType) => any | Promise<any>) | null, thisArg?: any): KoconutPrimitive<string>
  • Parameters

    • Default value separator: string = ", "
    • Default value prefix: string = ""
    • Default value postfix: string = ""
    • Default value limit: number = -1
    • Default value truncated: string = "..."
    • Default value transform: ((element: DataType) => any | Promise<any>) | null = null
    • Default value thisArg: any = null

    Returns KoconutPrimitive<string>

last

  • last(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType>

lastIndexOf

  • lastIndexOf(element: DataType): KoconutPrimitive<number>

lastOrNull

  • lastOrNull(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType | null>

minus

  • minus(element: DataType): KoconutSet<DataType>
  • minus(elements: Iterable<DataType>): KoconutSet<DataType>

minusElement

  • minusElement(element: DataType): KoconutSet<DataType>

partition

  • partition(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutPair<Set<DataType>, Set<DataType>>

plus

  • plus(element: DataType): KoconutSet<DataType>
  • plus(elements: Iterable<DataType>): KoconutSet<DataType>

plusElement

  • plusElement(element: DataType): KoconutSet<DataType>

random

  • random(): KoconutPrimitive<DataType>

randomOrNull

  • randomOrNull(): KoconutPrimitive<DataType | null>

reduce

  • reduce(operation: (acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutPrimitive<DataType>
  • Parameters

    • operation: (acc: DataType, element: DataType) => DataType | Promise<DataType>
        • (acc: DataType, element: DataType): DataType | Promise<DataType>
        • Parameters

          • acc: DataType
          • element: DataType

          Returns DataType | Promise<DataType>

    • Default value thisArg: any = null

    Returns KoconutPrimitive<DataType>

reduceIndexed

  • reduceIndexed(operation: (index: number, acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutPrimitive<DataType>
  • Parameters

    • operation: (index: number, acc: DataType, element: DataType) => DataType | Promise<DataType>
        • (index: number, acc: DataType, element: DataType): DataType | Promise<DataType>
        • Parameters

          • index: number
          • acc: DataType
          • element: DataType

          Returns DataType | Promise<DataType>

    • Default value thisArg: any = null

    Returns KoconutPrimitive<DataType>

reduceIndexedOrNull

  • reduceIndexedOrNull(operation: (index: number, acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Parameters

    • operation: (index: number, acc: DataType, element: DataType) => DataType | Promise<DataType>
        • (index: number, acc: DataType, element: DataType): DataType | Promise<DataType>
        • Parameters

          • index: number
          • acc: DataType
          • element: DataType

          Returns DataType | Promise<DataType>

    • Default value thisArg: any = null

    Returns KoconutPrimitive<DataType | null>

reduceOrNull

  • reduceOrNull(operation: (acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutPrimitive<DataType | null>

reversed

runningFold

  • runningFold<ResultDataType>(initial: ResultDataType, operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType
    • operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>
        • (acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

    Returns KoconutArray<ResultDataType>

runningFoldindexed

  • runningFoldindexed<ResultDataType>(initial: ResultDataType, operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType
    • operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>
        • (index: number, acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • index: number
          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

    Returns KoconutArray<ResultDataType>

runningReduce

  • runningReduce(operation: (acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutArray<DataType>

runningReduceIndexed

  • runningReduceIndexed(operation: (index: number, acc: DataType, element: DataType) => DataType | Promise<DataType>, thisArg?: any): KoconutArray<DataType>

scan

  • scan<ResultDataType>(initial: ResultDataType, operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType
    • operation: (acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>
        • (acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

    Returns KoconutArray<ResultDataType>

scanIndexed

  • scanIndexed<ResultDataType>(initial: ResultDataType, operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Type parameters

    • ResultDataType

    Parameters

    • initial: ResultDataType
    • operation: (index: number, acc: ResultDataType, element: DataType) => ResultDataType | Promise<ResultDataType>
        • (index: number, acc: ResultDataType, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • index: number
          • acc: ResultDataType
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

    Returns KoconutArray<ResultDataType>

shuffled

single

  • single(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType>

singleOrNull

  • singleOrNull(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType | null>

size

  • size(): KoconutPrimitive<number>

substarct

  • substarct(other: Iterable<DataType>): KoconutSet<DataType>

sumBy

  • sumBy(selector: (element: DataType) => number | Promise<number>, thisArg?: any): KoconutPrimitive<number>

union

  • union(other: Iterable<DataType>): KoconutSet<DataType>

validate

  • validate(data: Set<DataType> | null): Promise<void>

windowed

  • windowed(size: number): KoconutArray<Array<DataType>>
  • windowed(size: number, step: number): KoconutArray<Array<DataType>>
  • windowed(size: number, step: number, partialWindows: boolean): KoconutArray<Array<DataType>>
  • windowed<ResultDataType>(size: number, step: number, partialWindows: boolean, transform: (elements: Array<DataType>) => ResultDataType | Promise<ResultDataType>): KoconutArray<ResultDataType>
  • windowed<ResultDataType>(size: number, step: number, partialWindows: boolean, transform: (elements: Array<DataType>) => ResultDataType | Promise<ResultDataType>, thisArg: any): KoconutArray<ResultDataType>

withIndex

zip

  • zip<OtherDataType>(other: Iterable<OtherDataType>): KoconutArray<Pair<DataType, OtherDataType>>
  • zip<OtherDataType, ResultDataType>(other: Iterable<OtherDataType>, transform: (originalData: DataType, otherData: OtherDataType) => ResultDataType | Promise<ResultDataType>): KoconutArray<ResultDataType>
  • zip<OtherDataType, ResultDataType>(other: Iterable<OtherDataType>, transform: (originalData: DataType, otherData: OtherDataType) => ResultDataType | Promise<ResultDataType>, thisArg: any): KoconutArray<ResultDataType>

zipWithNext

  • zipWithNext(): KoconutArray<Pair<DataType, DataType>>
  • zipWithNext<ResultDataType>(transform: (firstData: DataType, secondData: DataType) => ResultDataType | Promise<ResultDataType>): KoconutArray<ResultDataType>
  • zipWithNext<ResultDataType>(transform: (firstData: DataType, secondData: DataType) => ResultDataType | Promise<ResultDataType>, thisArg: any): KoconutArray<ResultDataType>

Processor Methods

also

  • also(block: (data: Set<DataType>) => void | Promise<void>): Promise<Set<DataType> | 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: Set<DataType>) => void | Promise<void>

      A callback function that accepts an argument.

        • (data: Set<DataType>): void | Promise<void>
        • Parameters

          • data: Set<DataType>

          Returns void | Promise<void>

    Returns Promise<Set<DataType> | null>

let

  • let<ReturnType>(block: (data: Set<DataType>) => 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: Set<DataType>) => ReturnType | Promise<ReturnType>

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

        • (data: Set<DataType>): ReturnType | Promise<ReturnType>
        • Parameters

          • data: Set<DataType>

          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

  • Processes all the chained object and returns original KoconutSet instance.

    since

    1.0.15

    example
    const koconutSet = await KoconutSet
                        .of(1,2,3,4,5)
                        .retrieve()
    console.log(koconutSet)
    // ↑ KoconutSet {
    //   isValidated: true,
    //   data: Set { 1, 2, 3, 4, 5 },
    //   combinedDataWrapper: Set { 1, 2, 3, 4, 5 },
    //   mSize: 5,
    //   mIndices: [ 0, 1, 2, 3, 4 ]
    // }

    Returns Promise<KoconutSet<DataType>>

yield

  • yield(): Promise<Set<DataType>>
  • 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<Set<DataType>>

Selector Methods

elementAt

  • elementAt(index: number): KoconutPrimitive<DataType>
  • Returns an element at the given index or throws an KoconutIndexOutOfBoundsException if the index is out of bounds of this collection.

    throws

    KoconutIndexOutOfBoundsException -- When index is less than 0 or greater than lenth.

    since

    1.0.10

    example
    // Caes 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const elementAtIndex3OfArray = await koconutArray
                                        .elementAt(3)
                                        .yield()
    console.log(elementAtIndex3OfArray)
    // ↑ 4
    
    try {
        await koconutArray
                .elementAt(10)
                .yield()
    } catch(error) {
        console.log(error.name)
        // ↑ Koconut Index Out Of Bounds Exception
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const elementAtIndex2OfSet = await koconutSet
                                        .elementAt(2)
                                        .yield()
    console.log(elementAtIndex2OfSet)
    // ↑ 3
    
    try {
        await koconutSet
                .elementAt(-2)
                .yield()
    } catch(error) {
        console.log(error.name)
        // ↑ Koconut Index Out Of Bounds Exception
    }

    Parameters

    • index: number

      The index of element to search for.

    Returns KoconutPrimitive<DataType>

elementAtOrElse

  • elementAtOrElse(index: number, defaultValue: (index: number) => DataType | Promise<DataType>, thisArg?: any): KoconutPrimitive<DataType>
  • Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const elementAtIndex3OfArray = await koconutArray
                                    .elementAtOrElse(3, index => 0)
                                    .yield()
    console.log(elementAtIndex3OfArray)
    // ↑ 4
    
    const elementAtIndex10OfArray = await koconutArray
                                    .elementAtOrElse(10, index => 0)
                                    .yield()
    console.log(elementAtIndex10OfArray)
    // ↑ 0
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const elementAtIndex2OfSet = await koconutSet
                                    .elementAtOrElse(2, index => 0)
                                    .yield()
    console.log(elementAtIndex2OfSet)
    // ↑ 3
    
    const elementAtIndexNegative2OfSet = await koconutSet
                                    .elementAtOrElse(-2, index => 0)
                                    .yield()
    console.log(elementAtIndexNegative2OfSet)
    // ↑ 0

    Parameters

    • index: number

      The index of element to search for.

    • defaultValue: (index: number) => DataType | Promise<DataType>

      A callback function that accepts an argument. The method calls the defaultValue function when index is out of bounds.

        • (index: number): DataType | Promise<DataType>
        • Parameters

          • index: number

          Returns DataType | Promise<DataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the defaultValue. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

elementAtOrNull

  • elementAtOrNull(index: number): KoconutPrimitive<DataType | null>
  • Returns an element at the given index or null if the index is out of bounds of this collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const elementAtIndex3OfArray = await koconutArray
                                    .elementAtOrNull(3)
                                    .yield()
    console.log(elementAtIndex3OfArray)
    // ↑ 4
    
    const elementAtIndex10OfArray = await koconutArray
                                    .elementAtOrNull(10)
                                    .yield()
    console.log(elementAtIndex10OfArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const elementAtIndex2OfSet = await koconutSet
                                    .elementAtOrNull(2)
                                    .yield()
    console.log(elementAtIndex2OfSet)
    // ↑ 3
    
    const elementAtIndexNegative2OfSet = await koconutSet
                                    .elementAtOrNull(-2)
                                    .yield()
    console.log(elementAtIndexNegative2OfSet)
    // ↑ null

    Parameters

    • index: number

      The index of element to search for.

    Returns KoconutPrimitive<DataType | null>

find

  • find(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element matching the given predicate, or null if no such element was found.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const foundEventNumberOfArray = await koconutArray
                                    .find(eachNumber => eachNumber % 2 == 0)
                                    .yield()
    console.log(foundEventNumberOfArray)
    // ↑ 2
    
    const foundMultiplesOf10Array = await koconutArray
                                    .find(eachNumber => eachNumber % 10 == 0)
                                    .yield()
    console.log(foundMultiplesOf10Array)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const foundOddNumberOfSet = await koconutSet
                                    .find(eachNumber => eachNumber % 2 == 1)
                                    .yield()
    console.log(foundOddNumberOfSet)
    // ↑ 1
    
    const foundMultiplesOf10OfSet = await koconutSet
                                    .find(eachNumber => eachNumber % 10 == 0)
                                    .yield()
    console.log(foundMultiplesOf10OfSet)
    // ↑ null

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

findLast

  • findLast(predicate: (element: DataType) => boolean | Promise<boolean>, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the last element matching the given predicate, or null if no such element was found.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const lastEventNumberOfArray = await koconutArray
                                    .findLast(eachNumber => eachNumber % 2 == 0)
                                    .yield()
    console.log(lastEventNumberOfArray)
    // ↑ 4
    
    const lastMultiplesOf10Array = await koconutArray
                                    .findLast(eachNumber => eachNumber % 10 == 0)
                                    .yield()
    console.log(lastMultiplesOf10Array)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const lastOddNumberOfSet = await koconutSet
                                    .findLast(eachNumber => eachNumber % 2 == 1)
                                    .yield()
    console.log(lastOddNumberOfSet)
    // ↑ 5
    
    const lastMultiplesOf10OfSet = await koconutSet
                                    .findLast(eachNumber => eachNumber % 10 == 0)
                                    .yield()
    console.log(lastMultiplesOf10OfSet)
    // ↑ null

    Parameters

    • predicate: (element: DataType) => boolean | Promise<boolean>

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

        • (element: DataType): boolean | Promise<boolean>
        • Parameters

          • element: DataType

          Returns boolean | Promise<boolean>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

first

  • first(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType>
  • Returns the first element matching the given predicate. Or, if predicate is omitted method will just return the very first element of this collection. If source data is null or no element matching given predicate is found, it throws KoconutNoSuchElementException.

    throws

    KoconutNoSuchElementException -- When source data is empty or no element matching given predicate is found.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const firstNumberOfArray = await koconutArray
                                        .first()
                                        .yield()
    console.log(firstNumberOfArray)
    // ↑ 1
    
    const firstEventNumberOfArray = await koconutArray
                                .first(eachNumber => eachNumber % 2 == 0)
                                .yield()
    console.log(firstEventNumberOfArray)
    // ↑ 2
    
    try {
        await koconutArray
                .filter(eachNumber => eachNumber > 10)
                .first()
                .yield()
    } catch(error) {
        console.log(error.name)
        // ↑ Koconut No Such Element Exception
    }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const firstNumberOfSet = await koconutSet
                                    .first()
                                    .yield()
    console.log(firstNumberOfSet)
    // ↑ 1
    
    const firstOddNumberOfSet = await koconutSet
                                .first(eachNumber => eachNumber % 2 == 1)
                                .yield()
    console.log(firstOddNumberOfSet)
    // ↑ 1

    Parameters

    • Default value predicate: ((element: DataType) => boolean | Promise<boolean>) | null = null

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType>

firstOrNull

  • firstOrNull(predicate?: ((element: DataType) => boolean | Promise<boolean>) | null, thisArg?: any): KoconutPrimitive<DataType | null>
  • Returns the first element matching the given predicate. Or, if predicate is omitted method will just return the very first element of this collection. If source data is null or no element matching given predicate is found, it returns null.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const firstNumberOfArray = await koconutArray
                                        .firstOrNull()
                                        .yield()
    console.log(firstNumberOfArray)
    // ↑ 1
    
    const firstEventNumberOfArray = await koconutArray
                                .firstOrNull(eachNumber => eachNumber % 2 == 0)
                                .yield()
    console.log(firstEventNumberOfArray)
    // ↑ 2
    
    const firstNumberOfEmptyArray = await koconutArray
                                    .filter(eachNumber => eachNumber > 10)
                                    .firstOrNull()
                                    .yield()
    console.log(firstNumberOfEmptyArray)
    // ↑ null
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const firstNumberOfSet = await koconutSet
                                    .firstOrNull()
                                    .yield()
    console.log(firstNumberOfSet)
    // ↑ 1
    
    const firstOddNumberOfSet = await koconutSet
                                .firstOrNull(eachNumber => eachNumber % 2 == 1)
                                .yield()
    console.log(firstOddNumberOfSet)
    // ↑ 1

    Parameters

    • Default value predicate: ((element: DataType) => boolean | Promise<boolean>) | null = null

      A callback function that accepts an argument. The method calls the predicate one time for each element in object.

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the predicate. If thisArg is omitted, null is used as the this value.

    Returns KoconutPrimitive<DataType | null>

Transformer Methods

associate

  • associate<KeyType, ValueType>(transform: (element: DataType) => [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>, thisArg?: any): KoconutMap<KeyType, ValueType>
  • Returns a KoconutMap containing key-value paired Entry provided by transform function applied to elements of the given collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doubledValueMap = await koconutArray
                          .associate(eachNumber =>
                              [eachNumber, eachNumber * 2]
                              // ↑ Also can be
                              //   new Pair(eachNumber, eachNumber * 2)
                              //   Pair.from([eachNumber, eachNumber * 2])
                              //   new KoconutPair(eachNumber, eachNumber * 2)
                              //   new Entry(eachNumber, eachNumber * 2)
                              //   Entry.from([eachNumber, eachNumber * 2])
                              //   new KoconutEntry(eachNumber, eachNumber * 2)
                          )
                          .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledKeyMap = await koconutSet
                      .associate(eachNumber => [eachNumber * 2, eachNumber])
                      .yield()
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const squaredValueMap = await koconutArray2
                  .associate(async eachNumber => [eachNumber, eachNumber * eachNumber])
                  .yield()
    console.log(squaredValueMap)
    // ↑ Map { 1 => 1, 2 => 4, 3 => 9, 4 => 16, 5 => 25 }
    
    const squaredKeyMap = await koconutArray2
                  .associate(async eachNumber => new Promise<[number, number]>(resolve => {
                      resolve([eachNumber * eachNumber, eachNumber])
                  }))
                  .yield()
    console.log(squaredKeyMap)
    // ↑ Map { 1 => 1, 4 => 2, 9 => 3, 16 => 4, 25 => 5 }

    Type parameters

    • KeyType

    • ValueType

    Parameters

    • transform: (element: DataType) => [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>
        • Parameters

          • element: DataType

          Returns [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutMap<KeyType, ValueType>

associateBy

  • associateBy<KeyType, ValueType>(keySelector: (element: DataType) => KeyType | Promise<KeyType>, valueTransform?: ((element: DataType) => ValueType | Promise<ValueType>) | null, keySelectorThisArg?: any, valueTransformThisArg?: any): KoconutMap<KeyType, ValueType>
  • Returns a KoconutMap containing the elements from the given collection indexed by the key returned from keySelector function applied to each element. valueTransform callback function is optional. If it's not omitted the method returns a KoconutMap instance containing the values provied by the funcion and indexed by keySelector applied to elements of the given collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doubledKeyMap = await koconutArray
                          .associateBy(eachNumber => eachNumber * 2)
                          .yield()
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledKeyValueMap = await koconutSet
                              .associateBy(
                                  eachNumber => eachNumber * 2,
                                  eachNumber => eachNumber * 2
                              )
                              .yield()
    console.log(doubledKeyValueMap)
    // ↑ Map { 2 => 2, 4 => 4, 6 => 6, 8 => 8, 10 => 10 }
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const doubledKeySquaredValueMap = await koconutArray2
                      .associateBy(
                          async eachNumebr => eachNumebr * 2,
                          eachNumber => new Promise(resolve => {
                              resolve(eachNumber * eachNumber)
                          })
                      )
                      .yield()
    console.log(doubledKeySquaredValueMap)
    // ↑ Map { 2 => 1, 4 => 4, 6 => 9, 8 => 16, 10 => 25 }

    Type parameters

    • KeyType

    • ValueType = DataType

    Parameters

    • keySelector: (element: DataType) => KeyType | Promise<KeyType>

      A callback function that accepts an argument. The method calls the keySelector one time for each element in object.

        • (element: DataType): KeyType | Promise<KeyType>
        • Parameters

          • element: DataType

          Returns KeyType | Promise<KeyType>

    • Default value valueTransform: ((element: DataType) => ValueType | Promise<ValueType>) | null = null

      A callback function that accepts an argument. The method calls the valueTransform one time for each element in object it it's not omitted.

    • Default value keySelectorThisArg: any = null

      An object to which the this keyword can refer in the keySelector. If keySelectorThisArg is omitted, null is used as the this value.

    • Default value valueTransformThisArg: any = null

      An object to which the this keyword can refer in the valueTransform. If valueTransformThisArg is omitted, null is used as the this value.

    Returns KoconutMap<KeyType, ValueType>

associateByTo

  • associateByTo<KeyType, ValueType>(destination: Map<KeyType, ValueType>, keySelector: (element: DataType) => KeyType | Promise<KeyType>, valueTransform?: ((element: DataType) => ValueType | Promise<ValueType>) | null, keySelectorThisArg?: any, valueTransformThisArg?: any): KoconutSet<DataType>
  • Populates the given destination map with entries, where key is provided by keySelector function applied to each element. valueTransform callback function is optional. If it's omitted, each value of entry is same as the original data. Otherwise, the value is provided by the valueTransform function applied to elements of the given collcetion.

    note

    This method has different functionality with Kotlin. It'll return the original collection instance.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledKeyMap = new Map<number, number>()
    const stringKeyDoubledValueMap = new Map<string ,number>()
    const doubledKeySquaredValueMap = new Map<number, number>()
    const originalData = await koconutSet
              .associateByTo(
                  doubledKeyMap,
                  eachNumber => eachNumber * 2
              )
              .associateByTo(
                  stringKeyDoubledValueMap,
                  async eachNumber => eachNumber.toString(),
                  async eachNumber => eachNumber * 2
              )
              .associateByTo(
                  doubledKeySquaredValueMap,
                  eachNumber => new Promise(resolve => {
                      resolve(eachNumber * 2)
                  }),
                  eachNumber => new Promise(resolve => {
                      resolve(eachNumber * eachNumber)
                  })
              )
              .yield()
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    console.log(stringKeyDoubledValueMap)
    // ↑ Map { '1' => 2, '2' => 4, '3' => 6, '4' => 8, '5' => 10 }
    console.log(doubledKeySquaredValueMap)
    // ↑ Map { 2 => 1, 4 => 4, 6 => 9, 8 => 16, 10 => 25 }
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • KeyType

    • ValueType = DataType

    Parameters

    • destination: Map<KeyType, ValueType>

      Iterable destinaion. Map to be exact.

    • keySelector: (element: DataType) => KeyType | Promise<KeyType>

      A callback function that accepts an argument. The method calls the keySelector one time for each element in object.

        • (element: DataType): KeyType | Promise<KeyType>
        • Parameters

          • element: DataType

          Returns KeyType | Promise<KeyType>

    • Default value valueTransform: ((element: DataType) => ValueType | Promise<ValueType>) | null = null

      A callback function that accepts an argument. The method calls the valueTransform one time for each element in object it it's not omitted.

    • Default value keySelectorThisArg: any = null

      An object to which the this keyword can refer in the keySelector. If keySelectorThisArg is omitted, null is used as the this value.

    • Default value valueTransformThisArg: any = null

      An object to which the this keyword can refer in the valueTransform. If valueTransformThisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

associateTo

  • associateTo<KeyType, ValueType>(destination: Map<KeyType, ValueType>, transform: (element: DataType) => [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>, thisArg?: any): KoconutSet<DataType>
  • Populates the given destination map with entries, provided by transform function applied to elements of the given collection

    note

    This method has different functionality with Kotlin. It'll return the original collection instance.

    since

    1.0.10

    example
    const koconutSet = KoconutArray.of(1,2,3,4,5)
    
    const doubledValueMap = new Map<number, number>()
    const doubledKeyMap = new Map<number, number>()
    const squaredValueMap = new Map<number, number>()
    const originalData = await koconutSet
                  .associateTo(
                      doubledValueMap,
                      eachNumber => [eachNumber, eachNumber * 2]
                      // ↑ Also can be
                      //   new Pair(eachNumber, eachNumber * 2)
                      //   Pair.from([eachNumber, eachNumber * 2])
                      //   new KoconutPair(eachNumber, eachNumber * 2)
                      //   new Entry(eachNumber, eachNumber * 2)
                      //   Entry.from([eachNumber, eachNumber * 2])
                      //   new KoconutEntry(eachNumber, eachNumber * 2)
                  )
                  .associateTo(
                      doubledKeyMap,
                      async eachNumber => [eachNumber * 2, eachNumber]
                  )
                  .associateTo(
                      squaredValueMap,
                      eachNumber => new Promise(resolve => {
                          resolve([eachNumber, eachNumber * eachNumber])
                      })
                  )
                  .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    console.log(squaredValueMap)
    // ↑ Map { 1 => 1, 2 => 4, 3 => 9, 4 => 16, 5 => 25 }
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • KeyType

    • ValueType

    Parameters

    • destination: Map<KeyType, ValueType>

      Iterable destinaion. Map to be exact.

    • transform: (element: DataType) => [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>
        • Parameters

          • element: DataType

          Returns [KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Promise<[KeyType, ValueType] | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType> | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

associateWith

  • associateWith<ValueType>(valueSelector: (element: DataType) => ValueType | Promise<ValueType>, thisArg?: any): KoconutMap<DataType, ValueType>
  • Returns a KoconutMap where keys are original elements of the current object and values are produced by the valueSelector function applied to each element.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doubledValueMap = await koconutArray
                          .associateWith(eachNumber => eachNumber * 2)
                          .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const stringifiedValueMap = await koconutSet
                          .associateWith(eachNumber => eachNumber.toString())
                          .yield()
    console.log(stringifiedValueMap)
    // ↑ Map { 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5' }
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const squaredValueMap = await koconutArray2
                      .associateWith(async eachNumber => eachNumber * 2)
                      .yield()
    console.log(squaredValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    
    const trippledValueMap = await koconutArray2
                      .associateWith(eachNumber => new Promise(resolve => {
                          resolve(eachNumber * 3)
                      }))
                      .yield()
    console.log(trippledValueMap)
    // ↑ Map { 1 => 3, 2 => 6, 3 => 9, 4 => 12, 5 => 15 }

    Type parameters

    • ValueType

    Parameters

    • valueSelector: (element: DataType) => ValueType | Promise<ValueType>

      A callback function that accepts an argument. The method calls the valueSelector one time for each element in object.

        • (element: DataType): ValueType | Promise<ValueType>
        • Parameters

          • element: DataType

          Returns ValueType | Promise<ValueType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the valueSelector. If thisArg is omitted, null is used as the this value.

    Returns KoconutMap<DataType, ValueType>

associateWithTo

  • associateWithTo<ValueType>(destination: Map<DataType, ValueType>, valueSelector: (element: DataType) => ValueType | Promise<ValueType>, thisArg?: any): KoconutSet<DataType>
  • Populates the given destination map with entries for each element of the given collection, where key is the element itslef and value is provided by valueSelector function applied to that key.

    note

    This method has different functionality with Kotlin. It'll return the original collection instance.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledValueMap = new Map<number, number>()
    const stringifiedValueMap = new Map<number, string>()
    const squaredValueMap = new Map<number, number>()
    const originalData = await koconutSet
                      .associateWithTo(
                          doubledValueMap,
                          eachNumber => eachNumber * 2
                      )
                      .associateWithTo(
                          stringifiedValueMap,
                          async eachNumber => eachNumber.toString()
                      )
                      .associateWithTo(
                          squaredValueMap,
                          eachNumber => new Promise(resolve => {
                              resolve(eachNumber * eachNumber)
                          })
                      )
                      .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    console.log(stringifiedValueMap)
    // ↑ Map { 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5' }
    console.log(squaredValueMap)
    // ↑ Map { 1 => 1, 2 => 4, 3 => 9, 4 => 16, 5 => 25 }
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • ValueType

    Parameters

    • destination: Map<DataType, ValueType>

      Iterable destinaion. Map to be exact.

    • valueSelector: (element: DataType) => ValueType | Promise<ValueType>

      A callback function that accepts an argument. The method calls the valueSelector one time for each element in object.

        • (element: DataType): ValueType | Promise<ValueType>
        • Parameters

          • element: DataType

          Returns ValueType | Promise<ValueType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the valueSelector. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

chunked

  • chunked<ResultDataType>(size: number, transform: (elements: Array<DataType>) => ResultDataType | Promise<ResultDataType>, thisArg: any): KoconutArray<ResultDataType>
  • chunked(size: number): KoconutArray<Array<DataType>>
  • Splits this collection into a KoconutArray of Arrays each not exceeding the given size.

    throws

    KoconutInvalidArgumentException -- When size is not greater than 0.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const chunkedArray = await koconutArray
                          .chunked(3)
                          .yield()
    console.log(chunkedArray)
    // ↑ [ [ 1, 2, 3 ], [ 4, 5 ] ]
    
    try {
      await koconutArray
          .chunked(0)
          .yield()
    } catch(error) {
      console.log(error.name)
      // ↑ Koconut Invalid Argument Exception
    }
    
    // Case 2 -- Koconutset
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const chunkedSum = await koconutSet
          .chunked(
              3,
              numbers => numbers
                          .reduce(
                              (acc, eachNumber) => acc + eachNumber, 0
                          )
          )
          .yield()
    console.log(chunkedSum)
    // ↑ [ 6, 9 ]
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const chunkedMax = await koconutArray2
          .chunked(
              2,
              async numbers => await KoconutArray
                                      .from(numbers)
                                      .maxByOrNull(
                                          eachNumber => eachNumber
                                      )
                                      .yield()
          )
          .yield()
    console.log(chunkedMax)
    // ↑ [ 2, 4, 5 ]
    
    const chunkedMin = await koconutArray2
          .chunked(
              2,
              numbers => KoconutArray
                          .from(numbers)
                          .minByOrNull(
                              eachNumber => eachNumber
                          )
                          .yield()
          )
          .yield()
    console.log(chunkedMin)
    // ↑ [ 1, 3, 5 ]

    Type parameters

    • ResultDataType

    Parameters

    • size: number

      The number of elements to take in each Array, must be positive and can be greater than the number of elements in this collection.

    • transform: (elements: Array<DataType>) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the transform with chunked data array when it's not omitted.

        • (elements: Array<DataType>): ResultDataType | Promise<ResultDataType>
        • Parameters

          • elements: Array<DataType>

          Returns ResultDataType | Promise<ResultDataType>

    • thisArg: any

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

  • Parameters

    • size: number

    Returns KoconutArray<Array<DataType>>

flatMap

  • flatMap<ResultDataType>(transform: (element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>, thisArg?: any): KoconutArray<ResultDataType>
  • Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of("123", "45")
    
    const allNumberInArray = await koconutArray
                              .flatMap(eachString => eachString)
                              // ↑ The string itself can be used as Iterable<string>.
                              // If you want to make it clear, also possible to type
                              // as eachString => eachString.split('')
                              .map(parseInt)
                              .yield()
    console.log(allNumberInArray)
    // ↑ [ 1, 2, 3, 4, 5 ]
    
    // Case 2 - KoconutSet
    const koconutSet = KoconutSet.of("abc", "de")
    
    const allCharactersInSet = await koconutSet
                              .flatMap(eachString => eachString)
                              .yield()
    console.log(allCharactersInSet)
    // ↑ [ 'a', 'b', 'c', 'd', 'e' ]
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3,4,5)
                      .associateWith(eachNumber => eachNumber * 2)
    
    const allKeysAndValuesInMap = await koconutMap
                                  .flatMap(eachEntry => [eachEntry.key, eachEntry.value])
                                  .yield()
    console.log(allKeysAndValuesInMap)
    // ↑ [1, 2, 2, 4, 3, 6, 4, 8, 5, 10]
    
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(123, 987)
    
    const allDigitsInArray = await koconutArray2
                                  .flatMap(async eachNumber => {
                                      const digits = new Array<number>()
                                      while(eachNumber != 0) {
                                          digits.unshift(eachNumber % 10)
                                          eachNumber = Math.floor(eachNumber / 10)
                                      }
                                      return digits
                                  })
                                  .yield()
    console.log(allDigitsInArray)
    // ↑ [ 1, 2, 3, 9, 8, 7 ]
    
    const allNumberCharactersInArray = await koconutArray2
                                          .flatMap(eachNumber => new Promise<string>(resolve => {
                                              resolve(eachNumber.toString())
                                          }))
                                          .yield()
    console.log(allNumberCharactersInArray)
    // ↑ [ '1', '2', '3', '9', '8', '7' ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>
        • Parameters

          • element: DataType

          Returns Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

flatMapIndexed

  • flatMapIndexed<ResultDataType>(transform: (index: number, element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>, thisArg?: any): KoconutArray<ResultDataType>
  • Returns a KoconutArray of all elements yielded from results of transform function being invoked on each element of original collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(100, 101, 102)
    
    const allNumbersAndIndexOfArray = await koconutArray
                              .flatMapIndexed((eachIndex, eachNumber) =>
                                  [eachIndex, eachNumber]
                              )
                              .yield()
    console.log(allNumbersAndIndexOfArray)
    // ↑ [ 0, 100, 1, 101, 2, 102 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(100, 101, 102)
    
    const allNumbersAndIndexOfSet = await koconutSet
                              .flatMapIndexed((eachIndex, eachNumber) =>
                                  [eachIndex, eachNumber]
                              )
                              .yield()
    console.log(allNumbersAndIndexOfSet)
    // ↑ [ 0, 100, 1, 101, 2, 102 ]
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(123, 987)
    
    const allDigitsAndIndexInArray = await koconutArray2
                          .flatMapIndexed(async (eachIndex, eachNumber) => {
                              const digits = new Array<number>()
                              while(eachNumber != 0) {
                                  digits.unshift(eachNumber % 10)
                                  eachNumber = Math.floor(eachNumber / 10)
                              }
                              return [eachIndex, ...digits]
                          })
                          .yield()
    console.log(allDigitsAndIndexInArray)
    // ↑ [
    //     0, 1, 2, 3,
    //     1, 9, 8, 7
    //   ]
    
    const allNumberAndIndexCharactersInArray = await koconutArray2
              .flatMapIndexed((eachInex, eachNumber) => new Promise<string>(resolve => {
                  resolve(`${eachInex}${eachNumber}`)
              }))
              .yield()
    console.log(allNumberAndIndexCharactersInArray)
    // ↑ [
    //     '0', '1', '2',
    //     '3', '1', '9',
    //     '8', '7'
    //   ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (index: number, element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>
        • Parameters

          • index: number
          • element: DataType

          Returns Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

flatMapIndexedTo

  • flatMapIndexedTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (index: number, element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>, thisArg?: any): KoconutSet<DataType>
  • Appends all elements yielded from results of transform function being invoked on each element and its index in the original collection, to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of("123", "456")
    
    const allIndexAndNumbersInSet= new Array<number>()
    await koconutSet
          .flatMapIndexedTo(
              allIndexAndNumbersInSet,
              (eachIndex, eachElement) => [
                  eachIndex,
                  ...eachElement
                      .split('')
                      .map(eachCharacter => parseInt(eachCharacter))
              ]
          )
          .process()
    console.log(allIndexAndNumbersInSet)
    // ↑ [ 0, 1, 2, 3, 1, 4, 5, 6 ]

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (index: number, element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>
        • Parameters

          • index: number
          • element: DataType

          Returns Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

flatMapTo

  • flatMapTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>, thisArg?: any): KoconutSet<DataType>
  • Appends all elements yielded from results of transform function being invoked on each element of original collection, to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of("123", "456")
    
    const allNumbersInSet = new Array<number>()
    await koconutSet
          .flatMapTo(
              allNumbersInSet,
              (eachString) => eachString
                      .split('')
                      .map(eachCharacter => parseInt(eachCharacter))
          )
          .process()
    console.log(allNumbersInSet)
    // ↑ [ 1, 2, 3, 4, 5, 6 ]

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (element: DataType) => Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>
        • Parameters

          • element: DataType

          Returns Iterable<ResultDataType> | Promise<Iterable<ResultDataType>>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

map

  • map<ResultDataType>(transform: (element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Returns a list containing the results of applying the given transform function to each element in the original collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const doubledNumbersInArray = await koconutArray
                              .map(eachNumber => eachNumber * 2)
                              .yield()
    console.log(doubledNumbersInArray)
    // ↑ [ 2, 4, 6, 8, 10 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledNumbersInSet = await koconutSet
                              .map(eachNumber => eachNumber * 2)
                              .yield()
    console.log(doubledNumbersInSet)
    // ↑ [ 2, 4, 6, 8, 10 ]
    
    // Case 3 -- KoconutMap
    const koconutMap = KoconutArray.of(1,2,3,4,5)
                      .associate(eachNumber => [eachNumber, eachNumber * 2])
    
    const keyValueSumOfMap = await koconutMap
                          .map(eachEntry => eachEntry.key + eachEntry.value)
                          .yield()
    console.log(keyValueSumOfMap)
    // ↑ [ 3, 6, 9, 12, 15 ]
    
    // Case 4 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const squaredNumberInArray = await koconutArray2
                              .map(async eachNumber => eachNumber * eachNumber)
                              .yield()
    console.log(squaredNumberInArray)
    // ↑ [ 1, 4, 9, 16, 25 ]
    
    const trippledNumbersInArray = await koconutArray2
                                  .map(eachNumber => new Promise(resolve => {
                                      resolve(eachNumber * 3)
                                  }))
                                  .yield()
    console.log(trippledNumbersInArray)
    // ↑ [ 3, 6, 9, 12, 15 ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

mapIndexed

  • mapIndexed<ResultDataType>(transform: (index: number, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutArray<ResultDataType>
  • Retruns a list of all elements yielded from results of transform function beging invoked on each element and its index in the original collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const sumsOfIndexesAndNumbers = await koconutArray
                      .mapIndexed((eachIndex, eachNumber) => eachIndex + eachNumber)
                      .yield()
    console.log(sumsOfIndexesAndNumbers)
    // ↑ [ 1, 3, 5, 7, 9 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const productsOfIndexesAndNumbers = await koconutSet
                      .mapIndexed((eachIndex, eachNumber) => eachIndex * eachNumber)
                      .yield()
    console.log(productsOfIndexesAndNumbers)
    // ↑ [ 0, 2, 6, 12, 20 ]
    
    // Case 3 -- You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const averagesOfIndexesAndNumbers = await koconutArray2
                      .mapIndexed(async (eachIndex, eachNumber) => (eachIndex + eachNumber)/2)
                      .yield()
    console.log(averagesOfIndexesAndNumbers)
    // ↑ [ 0.5, 1.5, 2.5, 3.5, 4.5 ]
    
    const indexesMinusNumbers = await koconutArray2
                  .mapIndexed((eachIndex, eachNumber) => new Promise(resolve => {
                      resolve(eachIndex - eachNumber)
                  }))
                  .yield()
    console.log(indexesMinusNumbers)
    // ↑ [ -1, -1, -1, -1, -1 ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (index: number, element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • index: number
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

mapIndexedNotNull

  • mapIndexedNotNull<ResultDataType>(transform: (index: number, element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>, thisArg?: any): KoconutArray<ResultDataType>
  • Returns a KoconutArray containing only the results that are not null nor undefined of applying the given transform function to each element and its index in the original collection.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const sumsOfIndexesAndNumbersWhereNumberIsEven = await koconutArray
                      .mapIndexedNotNull((eachIndex, eachNumber) => {
                          if(eachNumber % 2 == 0)
                              return eachIndex + eachNumber
                          // return
                          // return null
                          // return undefined
                          // ↑ You can use any one of
                          //   them or just omit it.
                      })
                      .yield()
    console.log(sumsOfIndexesAndNumbersWhereNumberIsEven)
    // ↑ [ 3, 7 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const productsOfIndexesAndNumbersWhereIndexLessThan2 = await koconutSet
                      .mapIndexedNotNull((eachIndex, eachNumber) => {
                          if(eachIndex <= 2)
                              return eachIndex * eachNumber
                      })
                      .yield()
    console.log(productsOfIndexesAndNumbersWhereIndexLessThan2)
    // ↑ [ 0, 2, 6 ]
    
    // Case 3 - You can also do it asynchronously
    const koconutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const sumsOfIndexesAndNumbersWhereNumberIsOdd = await koconutArray2
                      .mapIndexedNotNull(async (eachIndex, eachNumber) => {
                          if(eachNumber % 2 == 1)
                              return eachIndex + eachNumber
                      })
                      .yield()
    console.log(sumsOfIndexesAndNumbersWhereNumberIsOdd)
    // ↑ [ 1, 5, 9 ]
    
    const squaredNumbersWhereIndesIsEven = await koconutArray2
              .mapIndexedNotNull((eachIndex, eachNumber) => new Promise<number | null>(resolve => {
                  if(eachIndex % 2 == 0)
                      resolve(eachNumber * eachNumber)
                  else resolve(null)
              }))
              .yield()
    console.log(squaredNumbersWhereIndesIsEven)
    // ↑ [ 1, 9, 25 ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (index: number, element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>
        • Parameters

          • index: number
          • element: DataType

          Returns ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

mapIndexedNotNullTo

  • mapIndexedNotNullTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (index: number, element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>, thisArg?: any): KoconutSet<DataType>
  • Applies the given transform function to each element and its index in the original collection and appends the results that are not null nor undefined to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const sumsOfIndexesAndNumbersWhereNumberIsEvent = new Array<number>()
    const prodcutsOfIndexesAndNumbersWhereIndexIsOdd = new Set<number>()
    const squaredNumbersWhereIndexLessThan3 = new Array<number>()
    const origianlData = await koconutSet
          .mapIndexedNotNullTo(
              sumsOfIndexesAndNumbersWhereNumberIsEvent,
              (eachIndex, eachNumber) => {
                  if(eachNumber % 2 == 0)
                      return eachIndex + eachNumber
                  // return
                  // return null
                  // return undefined
                  // ↑ You can use any one of
                  //   them or just omit it.
              }
          )
          .mapIndexedNotNullTo(
              prodcutsOfIndexesAndNumbersWhereIndexIsOdd,
              async (eachIndex, eachNumber) => {
                  if(eachIndex % 2 == 1)
                      return eachIndex * eachNumber
              }
          )
          .mapIndexedNotNullTo(
              squaredNumbersWhereIndexLessThan3,
              (eachIndex, eachNumber) => new Promise<number | null>(resolve => {
                  if(eachIndex <= 3)
                      resolve(eachNumber * eachNumber)
                  else resolve(null)
              })
          )
              .yield()
    console.log(sumsOfIndexesAndNumbersWhereNumberIsEvent)
    // ↑ [ 3, 7 ]
    console.log(prodcutsOfIndexesAndNumbersWhereIndexIsOdd)
    // ↑ Set { 2, 12 }
    console.log(squaredNumbersWhereIndexLessThan3)
    // ↑ [ 1, 4, 9, 16 ]
    console.log(origianlData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (index: number, element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>
        • Parameters

          • index: number
          • element: DataType

          Returns ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

mapIndexedTo

  • mapIndexedTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (index: number, element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutSet<DataType>
  • Applies the given transform function to each element and its index in the original collection and appends the results to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const sumsOfIndexesAndNumbers = new Array<number>()
    const originalData = await koconutSet
                      .mapIndexedTo(
                          sumsOfIndexesAndNumbers,
                          (eachIndex, eachNumber) => eachIndex + eachNumber
                      )
                      .yield()
    console.log(sumsOfIndexesAndNumbers)
    // ↑ [ 1, 3, 5, 7, 9 ]
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (index: number, element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts two arguments. The method calls the transform one time for each index and element in object.

        • (index: number, element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • index: number
          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

mapNotNull

  • mapNotNull<ResultDataType>(transform: (element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>, thisArg?: any): KoconutArray<ResultDataType>
  • Returns a list containing results that are not null nor undefined of applying the given transfrom function to each element in the original collection. You can use this method as filter then map.

    since

    1.0.10

    example
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)
    
    const squaredOddNumbersInArray = await koconutArray
                          .mapNotNull(eachNumber => {
                              if(eachNumber % 2 == 1)
                                  return eachNumber * eachNumber
                              // return
                              // return null
                              // return undefined
                              // ↑ You can use any one of
                              //   them or just omit it.
                          })
                          .yield()
    console.log(squaredOddNumbersInArray)
    // ↑ [ 1, 9, 25 ]
    
    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of("1", "54", "26", "5")
    
    const twoDigitsNumbersInSet = await koconutSet
                          .mapNotNull(eachString => {
                              if(eachString.length == 2)
                                  return parseInt(eachString)
                          })
                          .yield()
    console.log(twoDigitsNumbersInSet)
    // ↑ [ 54, 26 ]
    
    // Case 3 -- KoconutMap
    const KoconutMap = KoconutArray.of(1,2,3,4,5)
                  .associate(eachNumber => [eachNumber, eachNumber * 2])
    
    const oddKeyKeyValueSumInMap = await KoconutMap
                          .mapNotNull(eachEntry => {
                              if(eachEntry.key % 2 == 1)
                                  return eachEntry.key + eachEntry.value
                          })
                          .yield()
    console.log(oddKeyKeyValueSumInMap)
    // ↑ [ 3, 9, 15 ]
    
    // Case 4 -- You can also do it asynchronously
    const koocnutArray2 = KoconutArray.of(1,2,3,4,5)
    
    const squaredEvenNumbersInArray = await koocnutArray2
                              .mapNotNull(async eachNumber => {
                                  if(eachNumber % 2 == 0)
                                      return eachNumber * eachNumber
                              })
                              .yield()
    console.log(squaredEvenNumbersInArray)
    // ↑ [ 4, 16 ]
    
    const doubledOddNumbersInArray = await koocnutArray2
                          .mapNotNull(eachNumber => new Promise<number | null>(resolve => {
                              if(eachNumber % 2 == 1)
                                  resolve(eachNumber * 2)
                              else resolve(null)
                          }))
                          .yield()
    console.log(doubledOddNumbersInArray)
    // ↑ [ 2, 6, 10 ]

    Type parameters

    • ResultDataType

    Parameters

    • transform: (element: DataType) => ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>
        • Parameters

          • element: DataType

          Returns ResultDataType | void | null | undefined | Promise<ResultDataType | void | null | undefined>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutArray<ResultDataType>

mapNotNullTo

  • mapNotNullTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutSet<DataType>
  • Applies the given transform function to each element of the original collection and appends only the results that are not null nor undefined.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of("1", "12", "34", "5")
    
    const twoDigitsNumbers = Array<number>()
    const originalData = await koconutSet
                          .mapNotNullTo(
                              twoDigitsNumbers,
                              eachString => {
                                  if(eachString.length == 2)
                                      return parseInt(eachString)
                                  // return
                                  // return null
                                  // return undefined
                                  // ↑ You can use any one of
                                  //   them or just omit it.
                              }
                          )
                          .yield()
    console.log(twoDigitsNumbers)
    // ↑ [ 12, 34 ]
    console.log(originalData)
    // ↑ Set { '1', '12', '34', '5' }

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

mapTo

  • mapTo<ResultDataType>(destination: Array<ResultDataType> | Set<ResultDataType>, transform: (element: DataType) => ResultDataType | Promise<ResultDataType>, thisArg?: any): KoconutSet<DataType>
  • Applies the given transform function to each element of the original collection and appends the results to the given destination.

    since

    1.0.10

    example
    const koconutSet = KoconutSet.of(1,2,3,4,5)
    
    const doubledNumbers = new Array<number>()
    const originalData = await koconutSet
                      .mapTo(
                          doubledNumbers,
                          eachNumber => eachNumber * 2
                      )
                      .yield()
    console.log(doubledNumbers)
    // ↑ [ 2, 4, 6, 8, 10 ]
    console.log(originalData)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Type parameters

    • ResultDataType

    Parameters

    • destination: Array<ResultDataType> | Set<ResultDataType>

      Iterable destinaion. Array or Set to be exact.

    • transform: (element: DataType) => ResultDataType | Promise<ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each element in object.

        • (element: DataType): ResultDataType | Promise<ResultDataType>
        • Parameters

          • element: DataType

          Returns ResultDataType | Promise<ResultDataType>

    • Default value thisArg: any = null

      An object to which the this keyword can refer in the transform. If thisArg is omitted, null is used as the this value.

    Returns KoconutSet<DataType>

Generated using TypeDoc