Class KoconutMap<KeyType, ValueType>

Type Parameters

  • KeyType

  • ValueType

Hierarchy

  • KoconutIterable<[KeyType, ValueType], Entry<KeyType, ValueType>, Map<KeyType, ValueType>, Set<Entry<KeyType, ValueType>>>
    • KoconutMap

Constructors

  • Creates a new instance from iterable object. Inner data type could be an Array of two values([Key, Value]), a Pair or an Entry.

    Since

    1.0.11

    Example

    const stringAndNumberMap = new Map([
    ["a", 1], ["b", 2], ["c", 3]
    ])
    const stringAndNumber1 = new KoconutMap(stringAndNumberMap)
    // ↑ This is a Koconut string - number paired map.

    const stringAndNumber2 = new KoconutMap([
    ["a", 1], new Pair("b", 2), new Entry("c", 3)
    ])
    // ↑ This is a Koconut string - number paired map, too.

    const emptyStringAndNumberMap = new KoconutMap<string, number>()
    // ↑ This is an empty Koconut string - number paired map.

    Type Parameters

    • KeyType

    • ValueType

    Parameters

    • map: null | Iterable<[KeyType, ValueType] | Entry<KeyType, ValueType> | Pair<KeyType, ValueType>> = null

      An map-like iterable object to convert to a KoconutMap.

    Returns KoconutMap<KeyType, ValueType>

Accessors

  • get entries(): KoconutSet<Entry<KeyType, ValueType>>
  • Returns a KoconutSet contains every Entry.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const entries = await koconutMap
    .entries
    .yield()
    console.log(entries)
    // ↑ Set {
    // Entry { keyElement: 1, valueElement: 2 },
    // Entry { keyElement: 2, valueElement: 4 },
    // Entry { keyElement: 3, valueElement: 6 },
    // Entry { keyElement: 4, valueElement: 8 },
    // Entry { keyElement: 5, valueElement: 10 }
    // }

    Returns KoconutSet<Entry<KeyType, ValueType>>

  • get keys(): KoconutSet<KeyType>
  • Returns a KoconutSet contains all keys.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const keys = await koconutMap
    .keys
    .yield()
    console.log(keys)
    // ↑ Set { 1, 2, 3, 4, 5 }

    Returns KoconutSet<KeyType>

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<Entry<KeyType, ValueType>> = 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 entry yielding the largest value of the given function or throws KoconutNoSuchElementException if there are no entries.

    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<Entry<KeyType, ValueType>, string | number | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each entry 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 KoconutEntry<KeyType, ValueType>

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

    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<Entry<KeyType, ValueType>, string | number | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each entry 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 KoconutEntry<KeyType, ValueType>

  • 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>>

      A callback function that accepts two arguments. 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 KoconutEntry<KeyType, ValueType>

  • 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<Entry<KeyType, ValueType>>

      A callback function that accepts two arguments. 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 KoconutEntry<KeyType, ValueType>

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

    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<Entry<KeyType, ValueType>, string | number | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each entry 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 KoconutEntry<KeyType, ValueType>

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

    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<Entry<KeyType, ValueType>, string | number | KoconutComparable>

      A callback function that accepts an argument. The method calls the selector one time for each entry 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 KoconutEntry<KeyType, ValueType>

  • 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>, 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<Entry<KeyType, ValueType>>

      A callback function that accepts two arguments. 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 KoconutEntry<KeyType, ValueType>

  • 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<Entry<KeyType, ValueType>>

      A callback function that accepts two arguments. 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 KoconutEntry<KeyType, ValueType>

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<Entry<KeyType, ValueType>>

  • 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<Entry<KeyType, ValueType>>

Creator Methods

  • Creates a new instance from iterable object. Inner data type could be an Array of two values([Key, Value]), a Pair or an Entry.

    Returns

    Since

    1.0.11

    Example

    const stringAndNumberMap = new Map([
    ["a", 1], ["b", 2], ["c", 3]
    ])
    const stringAndNumber1 = KoconutMap.from(stringAndNumberMap)
    // ↑ This is a Koconut string - number paired map.

    const stringAndNumber2 = KoconutMap.from([
    ["a", 1], new Pair("b", 2), new Entry("c", 3)
    ])
    // ↑ This is a Koconut string - number paired map, too.

    const emptyStringAndNumberMap = KoconutMap.from<string, number>()
    // ↑ This is an empty Koconut string - number paired map.

    Type Parameters

    • KeyType

    • ValueType

    Parameters

    • source: null | Iterable<[KeyType, ValueType] | Entry<KeyType, ValueType> | Pair<KeyType, ValueType>> = null

      An map-like iterable object to convert to a KoconutMap.

    Returns KoconutMap<KeyType, ValueType>

  • Creates a new instance with given count as number of entries. count cannot be negative number. Each entry is provided from generator with given ordered index.

    Returns

    Throws

    KoconutInvalidArgumentException -- When count is less than 0.

    Since

    1.0.14

    Example

    const numberKeyStringValueMap = await KoconutMap.generate(
    5, i => [i, i.toString()]
    // ↑ Also can be
    // new Pair(i, i.toString())
    // Pair.from([i, i.toString()])
    // new KoconutPair(i, i.toString())
    // new Entry(i, i.toString())
    // Entry.from([i, i.toString()])
    // new KoconutEntry(i, i.toString())
    )
    .yield()
    console.log(numberKeyStringValueMap)
    // ↑ Map { 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4' }

    Type Parameters

    • KeyType

    • ValueType

    Parameters

    • count: number

      Number of values.

    • generator: Generator<[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 action one time for each ordered index.

    • thisArg: any = null

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

    Returns KoconutMap<KeyType, ValueType>

  • Creates a new instance from variable number of arguments. Inner data type could be an Array of two values([Key, Value]), a Pair or an Entry.

    Returns

    Since

    1.0.11

    Example

    const stringAndNumber = KoconutMap.of(
    ["a", 1], new Pair("b", 2), new Entry("c", 3)
    )
    // ↑ This is a Koconut string - number paired map.

    const emptyStringAndNumberMap = KoconutMap.of<string, number>()
    // ↑ This is an empty Koconut string - number paired map.

    Type Parameters

    • KeyType

    • ValueType

    Parameters

    • Rest ...data: ([KeyType, ValueType] | Entry<KeyType, ValueType> | Pair<KeyType, ValueType>)[]

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

    Returns KoconutMap<KeyType, ValueType>

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<Entry<KeyType, ValueType>>

      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<Entry<KeyType, ValueType>>

      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 this KoconutMap contains the given key.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const doesKoconutMapContainsKey4 = await koconutMap
    .contains(4)
    .yield()
    console.log(doesKoconutMapContainsKey4)
    // ↑ true

    const doesKoconutMapContainsKey7 = await koconutMap
    .contains(7)
    .yield()
    console.log(doesKoconutMapContainsKey7)
    // ↑ false

    Parameters

    • key: KeyType

      Key to search for.

    Returns KoconutBoolean

  • Checks if this KoconutMap contains the given key.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const doesKoconutMapContainsKey4 = await koconutMap
    .containsKey(4)
    .yield()
    console.log(doesKoconutMapContainsKey4)
    // ↑ true

    const doesKoconutMapContainsKey7 = await koconutMap
    .containsKey(7)
    .yield()
    console.log(doesKoconutMapContainsKey7)
    // ↑ false

    Parameters

    • key: KeyType

      Key to search for.

    Returns KoconutBoolean

  • Checks if this KoconutMap contains given value.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const doesKoconutMapContainsValue2 = await koconutMap
    .containsValue(2)
    .yield()
    console.log(doesKoconutMapContainsValue2)
    // ↑ true

    const doesKoconutMapContainsValue12 = await koconutMap
    .containsValue(12)
    .yield()
    console.log(doesKoconutMapContainsValue12)
    // ↑ false

    Parameters

    • value: ValueType

      Value 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<Entry<KeyType, ValueType>> = 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<Entry<KeyType, ValueType>>

      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 entry and returns the original collection itself afterwards. When you want to stop iteration in the meantime return false or BREAK.

    Returns

    Since

    1.0.10

    Example

    const KoconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const map = await KoconutMap
    .onEach(console.log)
    // ↑ Entry { keyElement: 1, valueElement: 2 }
    // Entry { keyElement: 2, valueElement: 4 }
    // Entry { keyElement: 3, valueElement: 6 }
    // Entry { keyElement: 4, valueElement: 8 }
    // Entry { keyElement: 5, valueElement: 10 }
    .onEach(async eachEntry => {
    if(eachEntry.key >= 3) return KoconutLoopSignal.BREAK
    console.log(eachEntry.value)
    })
    // ↑ 2
    // 4
    .onEach(eachEntry => new Promise(resolve => {
    if(eachEntry.value == 8) resolve(false)
    else {
    console.log(eachEntry.value)
    resolve()
    }
    }))
    // ↑ 2
    // 4
    // 6
    .yield()
    console.log(map)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    Parameters

    • action: Action<Entry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the action one time for each entry 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 KoconutMap<KeyType, ValueType>

Manipulator Methods

  • Returns a map containing only entries matching the given predicate.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const evenKeyEntries = await koconutMap
    .filter(eachEntry => eachEntry.key % 2 == 0)
    .yield()
    console.log(evenKeyEntries)
    // ↑ Map { 2 => 4, 4 => 8 }

    Parameters

    • predicate: Predicator<Entry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Returns a map containing all entries with key matching the given predicate.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const evenKeyMap = await koconutMap
    .filterKeys(eachKey => eachKey % 2 == 0)
    .yield()
    console.log(evenKeyMap)
    // ↑ Map { 2 => 4, 4 => 8 }

    Parameters

    • predicate: Predicator<KeyType>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Returns a map containing only entries not matching the given predicate.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const oddKeyEntries = await koconutMap
    .filterNot(eachEntry => eachEntry.key % 2 == 0)
    .yield()
    console.log(oddKeyEntries)
    // ↑ Map { 1 => 2, 3 => 6, 5 => 10 }

    Parameters

    • predicate: Predicator<Entry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Appends all entries not matching the given predicate to the given destination.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const oddKeyMap = new Map<number, number>()
    const originalMap = await koconutMap
    .filterNotTo(
    oddKeyMap,
    eachEntry => eachEntry.key % 2 == 0
    )
    .yield()
    console.log(oddKeyMap)
    // ↑ Map { 1 => 2, 3 => 6, 5 => 10 }
    console.log(originalMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    Parameters

    • destination: Map<KeyType, ValueType>

      Iterable destination. Map to be exact.

    • predicate: Predicator<Entry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Appends all entries matching the given predicate to the given destination.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const evenKeyMap = new Map<number, number>()
    const originalMap = await koconutMap
    .filterTo(
    evenKeyMap,
    eachEntry => eachEntry.key % 2 == 0
    )
    .yield()
    console.log(evenKeyMap)
    // ↑ Map { 2 => 4, 4 => 8 }
    console.log(originalMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    Parameters

    • destination: Map<KeyType, ValueType>

      Iterable destination. Map to be exact.

    • predicate: Predicator<Entry<KeyType, ValueType>>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Returns a map containing all entries with value matching the given predicate.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const valueGreaterThan5Map = await koconutMap
    .filterValues(eachValue => eachValue > 5)
    .yield()
    console.log(valueGreaterThan5Map)
    // ↑ Map { 3 => 6, 4 => 8, 5 => 10 }

    Parameters

    • predicate: Predicator<ValueType>

      A callback function that accepts an argument. The method calls the predicate one time for each entry 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 KoconutMap<KeyType, ValueType>

  • Returns a KoconutMap containing all entries of the original map except the entries the keys of which are contained in keys.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const key1ExceptedMap = await koconutMap
    .minus(1)
    .yield()
    console.log(key1ExceptedMap)
    // ↑ Map { 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    const key3And4ExpectedMap = await koconutMap
    .minus(3, 4)
    .yield()
    console.log(key3And4ExpectedMap)
    // ↑ Map { 1 => 2, 2 => 4, 5 => 10 }

    Parameters

    • Rest ...keys: KeyType[]

      Key data to except. It could be plural or singular.

    Returns KoconutMap<KeyType, ValueType>

  • Returns a KoconutMap by replacing or adding entries from given entries.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const key5ReplacedWith20Map = await koconutMap
    .plus(
    [5, 20]
    // ↑ Also can be
    // new Pair(5, 20)
    // Pair.from([5, 20])
    // new KoconutPair(5, 20)
    // new Entry(5, 20)
    // Entry.from([5, 20])
    // new KoconutEntry(5, 20)
    )
    .yield()
    console.log(key5ReplacedWith20Map)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 20 }

    const key6And7AddedMap = await koconutMap
    .plus(
    [6, 12],
    [7, 14]
    )
    .yield()
    console.log(key6And7AddedMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10, 6 => 12, 7 => 14 }

    Parameters

    • Rest ...entries: ([KeyType, ValueType] | Entry<KeyType, ValueType> | KoconutEntry<KeyType, ValueType> | Pair<KeyType, ValueType> | KoconutPair<KeyType, ValueType>)[]

      Entries to add or replace. It could be plural or singular.

    Returns KoconutMap<KeyType, ValueType>

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<Map<KeyType, ValueType>>

      A callback function that accepts an argument.

    Returns Promise<null | Map<KeyType, ValueType>>

  • 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<Map<KeyType, ValueType>, 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 object and returns original KoconutMap instance.

    Returns

    Since

    1.0.15

    Example

    const koconutMap = await KoconutArray
    .of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)
    .retrieve()
    console.log(koconutMap)
    // ↑ KoconutMap {
    // isValidated: true,
    // data: Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 },
    // combinedDataWrapper: Set {
    // Entry { keyElement: 1, valueElement: 2 },
    // Entry { keyElement: 2, valueElement: 4 },
    // Entry { keyElement: 3, valueElement: 6 },
    // Entry { keyElement: 4, valueElement: 8 },
    // Entry { keyElement: 5, valueElement: 10 }
    // },
    // mSize: 5,
    // mKeys: Set { 1, 2, 3, 4, 5 },
    // mValues: [ 2, 4, 6, 8, 10 ]
    // }

    Returns Promise<KoconutMap<KeyType, ValueType>>

  • 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<Map<KeyType, ValueType>>

Selector Methods

  • Returns the value corresponding to the given key, or null if such a key is not present in this KoconutMap.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const valueOfKey3 = await koconutMap
    .get(3)
    .yield()
    console.log(valueOfKey3)
    // ↑ 6

    const valueOfKey6 = await koconutMap
    .get(6)
    .yield()
    console.log(valueOfKey6)
    // ↑ null

    Parameters

    • key: KeyType

      Key to search for.

    Returns KoconutPrimitive<null | ValueType>

  • Returns the value to which the specified key is mapped, or defaultValue if the map contains no mapping for key.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const valueOfKey3 = await koconutMap
    .getOrDefault(3, 100)
    .yield()
    console.log(valueOfKey3)
    // ↑ 6

    const valueOfKey6 = await koconutMap
    .getOrDefault(6, 100)
    .yield()
    console.log(valueOfKey6)
    // ↑ 100

    Parameters

    • key: KeyType

      Key to search for.

    • defaultValue: ValueType

      Default value if no entry is found.

    Returns KoconutPrimitive<ValueType>

  • Returns the value for the given key, or the reuslt of the defaultValue function if there was no entry from the given key.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const valueOfKey3 = await koconutMap
    .getOrElse(3, () => 100)
    .yield()
    console.log(valueOfKey3)
    // ↑ 6

    const valueOfKey6 = await koconutMap
    .getOrElse(6, async () => 100)
    .yield()
    console.log(valueOfKey6)
    // ↑ 100

    const valueOfKey7 = await koconutMap
    .getOrElse(7, () => new Promise(resolve => {
    resolve(100)
    }))
    .yield()
    console.log(valueOfKey7)
    // ↑ 100

    Parameters

    • key: KeyType

      Key to search for.

    • defaultValue: Selector<void, ValueType>

      Callback function that generates default value. The method will call defaultValue if no entry is found.

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

Transformer Methods

  • 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<Entry<KeyType, ValueType>, 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>

  • Appends all entries yielded from results of transform function being invoked on each entry of original collection, to the given destination.

    Returns

    Since

    1.0.10

    Example

    const koconutSet = KoconutSet.of("123", "456")

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

    Type Parameters

    • ResultDataType

    Parameters

    • destination: ResultDataType[] | Set<ResultDataType>

      Iterable destination. Array or Set to be exact.

    • transform: Transformer<Entry<KeyType, ValueType>, Iterable<ResultDataType>>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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 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<Entry<KeyType, ValueType>, 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 new Map with entries having the keys obtained by applying the transform function to each entry in this object. The value of each of them would be the same as the original entry.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber)

    const stringifiedKeyMap = await koconutMap
    .mapKeys(eachEntry => eachEntry.key.toString())
    .yield()
    console.log(stringifiedKeyMap)
    // ↑ Map { '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5 }

    const doubledKeyMap = await koconutMap
    .mapKeys(async eachEntry => eachEntry.key * 2)
    .yield()
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }

    const sumOfKeyValueKeyMap = await koconutMap
    .mapKeys(eachEntry => new Promise(resolve => {
    resolve(eachEntry.key + eachEntry.value)
    }))
    .yield()
    console.log(sumOfKeyValueKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }

    Type Parameters

    • ResultDataType

    Parameters

    • transform: Transformer<Entry<KeyType, ValueType>, ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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<ResultDataType, ValueType>

  • Populates the given destination map with entries having keys obtained by applying the transform function to each entry in this object. The value of each of them would be the same as the original entry.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber)

    const stringifiedKeyMap = new Map<string, number>()
    const doubledKeyMap = new Map<number, number>()
    const sumOfKeyValueKeyMap = new Map<number, number>()
    const originalData = await koconutMap
    .mapKeysTo(
    stringifiedKeyMap,
    eachEntry => eachEntry.key.toString()
    )
    .mapKeysTo(
    doubledKeyMap,
    async eachEntry => eachEntry.key * 2
    )
    .mapKeysTo(
    sumOfKeyValueKeyMap,
    eachEntry => new Promise(resolve => {
    resolve(eachEntry.key + eachEntry.value)
    })
    )
    .yield()
    console.log(stringifiedKeyMap)
    // ↑ Map { '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5 }
    console.log(doubledKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    console.log(sumOfKeyValueKeyMap)
    // ↑ Map { 2 => 1, 4 => 2, 6 => 3, 8 => 4, 10 => 5 }
    console.log(originalData)
    // ↑ Map { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 }

    Type Parameters

    • ResultDataType

    Parameters

    • destination: Map<ResultDataType, ValueType>

      Iterable destination. Map to be exact.

    • transform: Transformer<Entry<KeyType, ValueType>, ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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 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<Entry<KeyType, ValueType>, 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>

  • Applies the given transform function to each entry of the original collection and appends the results to the given destination.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber * 2)

    const oddKeyKeyValueSum = new Array<number>()
    const originalData = await koconutMap
    .mapNotNullTo(
    oddKeyKeyValueSum,
    eachEntry => {
    if(eachEntry.key % 2 == 1)
    return eachEntry.key + eachEntry.value
    // return
    // return null
    // return undefined
    // ↑ You can use any one of
    // them or just omit it.
    }
    )
    .yield()
    console.log(oddKeyKeyValueSum)
    // ↑ [ 3, 9, 15 ]
    console.log(originalData)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    Type Parameters

    • ResultDataType

    Parameters

    • destination: ResultDataType[] | Set<ResultDataType>

      Iterable destination. Array or Set to be exact.

    • transform: Transformer<Entry<KeyType, ValueType>, null | ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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>

  • Applies the given transform function to each entry of the original collection and appends the results to the given destination.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associate(eachNumber => [eachNumber, eachNumber * 2])

    const sumsOfKeyValue = new Array<number>()
    const originalData = await koconutMap
    .mapTo(
    sumsOfKeyValue,
    eachEntry => eachEntry.key + eachEntry.value
    )
    .yield()
    console.log(sumsOfKeyValue)
    // ↑ [ 3, 6, 9, 12, 15 ]
    console.log(originalData)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    Type Parameters

    • ResultDataType

    Parameters

    • destination: ResultDataType[] | Set<ResultDataType>

      Iterable destination. Array or Set to be exact.

    • transform: Transformer<Entry<KeyType, ValueType>, 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 KoconutMap<KeyType, ValueType>

  • Returns a new Map with entries having the keys of this object and the values obtained by applying the transform function to each entry.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber)

    const doubledValueMap = await koconutMap
    .mapValues(eachEntry => eachEntry.value * 2)
    .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }

    const stringifiedValueMap = await koconutMap
    .mapValues(async eachEntry => eachEntry.value.toString())
    .yield()
    console.log(stringifiedValueMap)
    // ↑ Map { 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5' }

    const squaredValueMap = await koconutMap
    .mapValues(eachEntry => new Promise(resolve => {
    resolve(eachEntry.value * eachEntry.value)
    }))
    .yield()
    console.log(squaredValueMap)
    // ↑ Map { 1 => 1, 2 => 4, 3 => 9, 4 => 16, 5 => 25 }

    Type Parameters

    • ResultDataType

    Parameters

    • transform: Transformer<Entry<KeyType, ValueType>, ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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, ResultDataType>

  • Populates the given destination Map with the entries having the keys of this object and the values obtained by applying the transform function to each entry.

    Returns

    Since

    1.0.10

    Example

    const koconutMap = KoconutArray.of(1,2,3,4,5)
    .associateWith(eachNumber => eachNumber)

    const doubledValueMap = new Map<number, number>()
    const stringifiedValueMap = new Map<number, string>()
    const squaredValueMap = new Map<number, number>()
    const originalData = await koconutMap
    .mapValuesTo(
    doubledValueMap,
    eachEntry => eachEntry.value * 2
    )
    .mapValuesTo(
    stringifiedValueMap,
    async eachEntry => eachEntry.value.toString()
    )
    .mapValuesTo(
    squaredValueMap,
    eachEntry => new Promise(resolve => {
    resolve(eachEntry.value * eachEntry.value)
    })
    )
    .yield()
    console.log(doubledValueMap)
    // ↑ Map { 1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10 }
    console.log(stringifiedValueMap)
    // ↑ Map { 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5' }
    console.log(squaredValueMap)
    // ↑ Map { 1 => 1, 2 => 4, 3 => 9, 4 => 16, 5 => 25 }
    console.log(originalData)
    // ↑ Map { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 }

    Type Parameters

    • ResultDataType

    Parameters

    • destination: Map<KeyType, ResultDataType>

      Iterable destination. Map to be exact.

    • transform: Transformer<Entry<KeyType, ValueType>, ResultDataType>

      A callback function that accepts an argument. The method calls the transform one time for each entry 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>

Generated using TypeDoc