New Functions
Add concat function #388
Flattens and filters nullish values from arguments.
import { concat } from 'radashi'
const result = concat('a', null, ['b', undefined], 'c')
// => ['a', 'b', 'c']Add pluck function #376
Map an array of objects to an array of arrays.
import { pluck } from 'radashi'
const gods = [
{ name: 'Ra', power: 100 },
{ name: 'Zeus', power: 98 },
]
const names = pluck(gods, ['name'])
// => [['Ra'], ['Zeus']]Thanks to @nusohiro for the contribution!
Fixed
Fix mapify index argument #384
Ensure the index argument passed to mapify's 2nd callback is the actual array index.
import { mapify } from 'radashi'
const list = [
{ id: 'a', word: 'hello' },
{ id: 'a', word: 'bye' },
{ id: 'a', word: 'oh' },
]
const result = mapify(
list,
x => x.id,
(x, i) => x.word + i,
)
// => Map { 'a' => 'oh2' }Thanks to @Yukiniro for the contribution!
Avoid infinite loop in cluster when size is 0 #397
The cluster function now correctly handles the case where the size is 0 or less by returning an empty array.
import { cluster } from 'radashi'
const result = cluster([1, 2, 3], 0)
// => []Thanks to @fResult for the contribution!
Types
Improve cluster type inference #389
The cluster function now provides precise type inference for common cluster sizes (1-8) using tuple types.
import { cluster } from 'radashi'
const result = cluster(['a', 'b', 'c', 'd'], 2)
// ^? [string, string][]Thanks to @fResult for the contribution!