Example 1 — Split at the First 2 (Official Sample)
Cut once, right before the first item equal to 2.
const list = [1, 2, 3, 1, 2, 3];
console.log(R.splitWhen(R.equals(2), list)); // [[1], [2, 3, 1, 2, 3]]
console.log(list); // [1, 2, 3, 1, 2, 3] How It Works
- The test.
R.equals(2)returnstrueonly for the value2. - Collect misses.
1fails the test, so it goes into part 1. - First hit. The
2at index 1 passes, so the cut happens just before it. - One cut only. The second
2stays in part 2, andlistis unchanged.
