Example 1 — Official Duplicate
Turn every number into a pair, then get one flat list — the main sample from the Ramda docs.
const duplicate = (n) => [n, n];
console.log(R.chain(duplicate, [1, 2, 3]));
// [1, 1, 2, 2, 3, 3] How It Works
- Map.
duplicateruns on each number:1 → [1, 1],2 → [2, 2],3 → [3, 3]. - Flatten.
R.chainjoins those three pairs in order. - Result. Three inputs become six numbers in one list.
- Unchanged input. The original
[1, 2, 3]is not modified.
