If you have several lists that you need to run through a side-effect, it's usually a good choice to concatenate these lists together. It's easier for side-effects to iterate over one collection than several of them.
The best way to think about concatenating lists together is as basic addition. You're effectively adding lists together, resulting in a larger list. You use the concat()
method to concatenate lists:
const myList1 = List.of(1, 2, 3); const myList2 = List.of(4, 5, 6); const myList3 = List.of(7, 8, 9); const myCombinedList = myList1.concat( myList2, myList3 ); console.log('myList1', myList1.toJS()); // -> myList1 [ 1, 2, 3 ] console.log('myList2', myList2.toJS()); // -> myList2 [ 4, 5, 6 ] console.log('myList3', myList3.toJS()); // -> myList3 [ 7, 8, 9 ] console.log('myCombinedList', myCombinedList.toJS()); // -> myCombinedList [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
Now our side-effect only needs to worry about iterating...