Class KoconutCollection<DataType, WrapperType>Internal

Type Parameters

  • DataType

  • WrapperType extends DataType[] | Sequence<DataType> | Set<DataType>

Hierarchy

Constructors

Methods - Accumulator

Methods - Calculator

Methods - Caster

Methods - Inspector

Methods - Iterator

Methods - Other

Methods - Processor

Methods - Selector

Methods - Transformer

Constructors

Accumulator Methods

  • Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

    Returns

    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: Operator<DataType, 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.

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

  • Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

    Returns

    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: IndexedOperator<DataType, 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.

    • 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

  • Returns the number of the elements matching the given predicate. If the predicate is ommitted it'll returns the whole number of elements.

    Returns

    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

    • predicate: null | Predicator<DataType> = null

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

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

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

    Returns

    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 longestStringOfSet = await koconutSet
    .maxBy(eachString => eachString.length)
    .yield()
    console.log(longestStringOfSet)
    // ↑ 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: Selector<DataType, string | number | KoconutComparable>

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

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

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

    Returns

    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 longestStringOfSet = await koconutSet
    .maxByOrNull(eachString => eachString.length)
    .yield()
    console.log(longestStringOfSet)
    // ↑ 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: Selector<DataType, string | number | KoconutComparable>

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

    • 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<null | DataType>

  • 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.

    Returns

    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

    Type Parameters

    Parameters

    • selector: Selector<DataType, string | number | ComparableType>

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

    • 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<string | number | ComparableType>

  • 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.

    Returns

    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

    Type Parameters

    Parameters

    • selector: Selector<DataType, string | number | ComparableType>

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

    • 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<null | string | number | ComparableType>

  • 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.

    Returns

    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: Selector<DataType, ResultDataType>

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

    • comparator: Comparator<ResultDataType>

      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.

    • 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.

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

  • 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.

    Returns

    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: Selector<DataType, ResultDataType>

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

    • comparator: Comparator<ResultDataType>

      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.

    • 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.

    • 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<null | ResultDataType>

  • Returns the first element having the largest value according to the provided comparator or throws KoconutNoSuchElementException if elements are empty.

    Returns

    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: Comparator<DataType>

      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.

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

  • Returns the first element having the largest value according to the provided comparator or null if elements are empty.

    Returns

    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: Comparator<DataType>

      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.

    • 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<null | DataType>

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

    Returns

    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: Selector<DataType, string | number | KoconutComparable>

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

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

  • Returns the first element yielding the smallest value of the given function or null if there are no elements.

    Returns

    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 smallestNumberOfArray2 = await koconutArray2
    .minByOrNull(async eachNumber => eachNumber)
    .yield()
    console.log(smallestNumberOfArray2)
    // ↑ 19

    const smallest1sDigitNumberOfArray2 = await koconutArray2
    .minByOrNull(eachNumber => new Promise(resolve => {
    resolve(eachNumber % 10)
    }))
    .yield()
    console.log(smallest1sDigitNumberOfArray2)
    // ↑ 32

    Parameters

    • selector: Selector<DataType, string | number | KoconutComparable>

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

    • 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<null | DataType>

  • 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.

    Returns

    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

    Type Parameters

    Parameters

    • selector: Selector<DataType, string | number | ComparableType>

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

    • 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<string | number | ComparableType>

  • 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.

    Returns

    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

    Type Parameters

    Parameters

    • selector: Selector<DataType, string | number | ComparableType>

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

    • 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<null | string | number | ComparableType>

  • 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.

    Returns

    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: Selector<DataType, ResultDataType>

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

    • comparator: Comparator<ResultDataType>

      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.

    • 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.

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

  • 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.

    Returns

    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: Selector<DataType, ResultDataType>

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

    • comparator: Comparator<ResultDataType>

      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.

    • 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.

    • 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<null | ResultDataType>

  • Returns the first element having the smallest value according to the provided comparator or throws KoconutNoSuchElementException if elements are empty.

    Returns

    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: Comparator<DataType>

      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.

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

  • Returns the first element having the smallest value according to the provided comparator or null if elements are empty.

    Returns

    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: Comparator<DataType>

      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.

    • 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<null | DataType>

Caster Methods

  • Creates an KoconutArray instance that wraps original data.

    Returns

    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>

  • Creates an KoconutSet instance that wraps original data.

    Returns

    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>

Inspector Methods

  • Return true if all elements match te given predicate.

    Returns

    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: Predicator<DataType>

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

    • 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

  • Returns true if the collection has at least one element matches the given predicate.

    Returns

    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: Predicator<DataType>

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

    • 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

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

    Returns

    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

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

    Returns

    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

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

    Returns

    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

  • Returns true if the collection is not empty.

    Returns

    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

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

    Returns

    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

  • 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.

    Returns

    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

    • predicate: null | Predicator<DataType> = null

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

    • 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

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

    Returns

    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: Action<DataType>

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

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

  • 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 BREAK.

    Returns

    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: IndexedAction<DataType>

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

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

Other Methods

Processor Methods

  • 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: Processor<WrapperType>

      A callback function that accepts an argument.

    Returns Promise<null | WrapperType>

  • 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: Selector<WrapperType, ReturnType>

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

    Returns Promise<ReturnType>

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

  • 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<WrapperType>

Selector Methods

  • Returns an element at the given index or throws an KoconutIndexOutOfBoundsException if the index is out of bounds of this collection.

    Returns

    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>

  • 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.

    Returns

    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: Selector<number, DataType>

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

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

  • Returns an element at the given index or null if the index is out of bounds of this collection.

    Returns

    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<null | DataType>

  • Returns the first element matching the given predicate, or null if no such element was found.

    Returns

    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: Predicator<DataType>

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

    • 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<null | DataType>

  • Returns the last element matching the given predicate, or null if no such element was found.

    Returns

    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: Predicator<DataType>

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

    • 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<null | 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.

    Returns

    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

    • predicate: null | Predicator<DataType> = null

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

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

  • 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.

    Returns

    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

    • predicate: null | Predicator<DataType> = null

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

    • 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<null | DataType>

  • Returns first index of element. or -1 if the collection does not contains element.

    Returns

    Since

    1.0.10

    Example

    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)

    const indexOf3 = await koconutArray
    .indexOf(3)
    .yield()
    console.log(indexOf3)
    // ↑ 2

    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)

    const indexOf10 = await koconutSet
    .indexOf(10)
    .yield()
    console.log(indexOf10)
    // ↑ -1

    Parameters

    • elementToFind: DataType

      The element to search for.

    Returns KoconutPrimitive<number>

  • Returns index of the first element matching the given predicate, or -1 if the collection does not contain such element.

    Returns

    Since

    1.0.10

    Example

    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)

    const indexOfFirstEven = await koconutArray
    .indexOfFirst(eachNumber => eachNumber % 2 == 0)
    .yield()
    console.log(indexOfFirstEven)
    // ↑ 1

    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)

    const indexOfFirstOdd = await koconutSet
    .indexOfFirst(eachNumber => eachNumber % 2 == 1)
    .yield()
    console.log(indexOfFirstOdd)
    // ↑ 0

    Parameters

    • predicate: Predicator<DataType>

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

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

  • Returns index of the last element matching the given predicate, or -1 if the collection does not contain such element.

    Returns

    Since

    1.0.10

    Example

    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)

    const indexOfLastEven = await koconutArray
    .indexOfLast(eachNumber => eachNumber % 2 == 0)
    .yield()
    console.log(indexOfLastEven)
    // ↑ 3

    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)

    const indexOfLastOdd = await koconutSet
    .indexOfLast(eachNumber => eachNumber % 2 == 1)
    .yield()
    console.log(indexOfLastOdd)
    // ↑ 4

    Parameters

    • predicate: Predicator<DataType>

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

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

Transformer Methods

  • Returns a KoconutMap containing key-value paired Entry provided by transform function applied to elements of the given collection.

    Returns

    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: Transformer<DataType, [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.

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

  • 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 provide by the function and indexed by keySelector applied to elements of the given collection.

    Returns

    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 eachNumber => eachNumber * 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: Selector<DataType, KeyType>

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

    • valueTransform: null | Transformer<DataType, ValueType> = 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.

    • 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.

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

  • Returns a KoconutMap where keys are original elements of the current object and values are produced by the valueSelector function applied to each element.

    Returns

    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 tripledValueMap = await koconutArray2
    .associateWith(eachNumber => new Promise(resolve => {
    resolve(eachNumber * 3)
    }))
    .yield()
    console.log(tripledValueMap)
    // ↑ Map { 1 => 3, 2 => 6, 3 => 9, 4 => 12, 5 => 15 }

    Type Parameters

    • ValueType

    Parameters

    • valueSelector: Selector<DataType, ValueType>

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

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

  • Splits this collection into a KoconutArray of Arrays each not exceeding the given size.

    Returns

    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: null | Transformer<DataType[], ResultDataType>

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

    • 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<DataType[] | ResultDataType>

  • Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

    Returns

    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: Transformer<DataType, Iterable<ResultDataType>>

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

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

  • Returns a KoconutArray of all elements yielded from results of transform function being invoked on each element of original collection.

    Returns

    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: IndexedTransformer<DataType, Iterable<ResultDataType>>

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

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

  • Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values. If valueTransform is omitted, the value of each entry would be original element.

    Returns

    Since

    1.0.10

    Example

    // Case 1 -- KoconutArray
    // Case 1 -- KoconutArray
    const koconutArray = KoconutArray.of(1,2,3,4,5)

    const groupedByOddParity = await koconutArray
    .groupBy(eachNumber => eachNumber % 2 == 1)
    .yield()
    console.log(groupedByOddParity)
    // ↑ Map { true => [ 1, 3, 5 ], false => [ 2, 4 ] }

    // Case 2 -- KoconutSet
    const koconutSet = KoconutSet.of(1,2,3,4,5)

    const groupedByEvenParityToString = await koconutSet
    .groupBy(
    eachNumber => eachNumber % 2 == 0,
    eachNumber => eachNumber.toString()
    )
    .yield()
    console.log(groupedByEvenParityToString)
    // ↑ Map { false => [ '1', '3', '5' ], true => [ '2', '4' ] }

    Type Parameters

    • KeyType

    • ValueType = DataType

    Parameters

    • keySelector: Selector<DataType, KeyType>

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

    • valueTransform: null | Transformer<DataType, ValueType> = 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.

    • 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.

    • 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[]>

  • Returns a list containing the results of applying the given transform function to each element in the original collection.

    Returns

    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: Transformer<DataType, ResultDataType>

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

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

  • Returns a list of all elements yielded from results of transform function being invoked on each element and its index in the original collection.

    Returns

    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: IndexedTransformer<DataType, ResultDataType>

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

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

  • 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.

    Returns

    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 squaredNumbersWhereIndexIsEven = await koconutArray2
    .mapIndexedNotNull((eachIndex, eachNumber) => new Promise<number | null>(resolve => {
    if(eachIndex % 2 == 0)
    resolve(eachNumber * eachNumber)
    else resolve(null)
    }))
    .yield()
    console.log(squaredNumbersWhereIndexIsEven)
    // ↑ [ 1, 9, 25 ]

    Type Parameters

    • ResultDataType

    Parameters

    • transform: IndexedTransformer<DataType, undefined | null | void | ResultDataType>

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

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

  • 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.

    Returns

    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: Transformer<DataType, undefined | null | void | ResultDataType>

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

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

Generated using TypeDoc