mAppendAll
mAppendAll
(appended: array) => (base: array) => base
Push the contents of one array onto another
Consider appendAll instead.
This is for the uncommon case where mutatingbase
is required.const arr = ['a'] const appendBC = mAppendAll(['b', 'c']) const mutatedArr = appendBC(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['a'] const appendBC = mAppendAll(['b', 'c']) const mutatedArr = appendBC(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['a'] const appendBC = mAppendAll(['b', 'c']) const mutatedArr = appendBC(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['a'] const appendBC = mAppendAll(['b', 'c']) const mutatedArr = appendBC(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
Sometimes we want to mutate an array by pushing values onto it. Below, our apartment is receiving a few fliers. Let's update our mailboxes with the junkmail.
const mailboxes = { 101: ['water bill'], 102: ['birthday card'], 103: [], } const addJunkmail = mAppendAll(['pizza coupon', 'housing ad']) const deliverJunkmail = forEach(addJunkmail) deliverJunkmail(mailboxes) console.log(mailboxes) // is { // 101: water bill, pizza coupon, housing ad // 102: birthday card, pizza coupon, housing ad // 103: pizza coupon, housing ad // }
type Mailboxes = Record<number, string[]> const mailboxes = { 101: ['water bill'], 102: ['birthday card'], 103: [], } const addJunkmail = mAppendAll(['pizza coupon', 'housing ad'])<string[]> const deliverJunkmail = forEach(addJunkmail)<Mailboxes> deliverJunkmail(mailboxes) console.log(mailboxes) // is { // 101: water bill, pizza coupon, housing ad // 102: birthday card, pizza coupon, housing ad // 103: pizza coupon, housing ad // }
const mailboxes = { 101: ['water bill'], 102: ['birthday card'], 103: [], } const addJunkmail = mAppendAll([ 'pizza coupon', 'housing ad', ]) const deliverJunkmail = forEach(addJunkmail) deliverJunkmail(mailboxes) console.log(mailboxes) // is { // 101: water bill, pizza coupon, housing ad // 102: birthday card, pizza coupon, housing ad // 103: pizza coupon, housing ad // }
type Mailboxes = Record<number, string[]> const mailboxes = { 101: ['water bill'], 102: ['birthday card'], 103: [], } const addJunkmail = mAppendAll([ 'pizza coupon', 'housing ad', ])<string[]> const deliverJunkmail = forEach( addJunkmail )<Mailboxes> deliverJunkmail(mailboxes) console.log(mailboxes) // is { // 101: water bill, pizza coupon, housing ad // 102: birthday card, pizza coupon, housing ad // 103: pizza coupon, housing ad // }