How to use the splitWhen function from ramda

Find comprehensive JavaScript ramda.splitWhen code examples handpicked from public code repositorys.

6
7
8
9
10
11
12
13
14
15
16
17
18
});


// --------------------------------------------


function parse(lines) {
    const sections = R.splitWhen(R.isEmpty, lines);


    const stackElements = sections[0].map(R.splitEvery(4));
    const stackElementsTransposed = R.transpose(stackElements)
    
fork icon0
star icon0
watch icon0

+ 3 other calls in file

4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
 * @param {Function} pred The predicate that determines where the array is split.
 * @param {Array} list The array to be split.
 * @return {Array}
 * @example
 *
 *      R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]);   //=> [[1], [2, 3, 1, 2, 3]]
 */
var splitWhen = _curry2(function splitWhen(pred, list) {
    var idx = 0;
    var len = list.length;
fork icon0
star icon0
watch icon0

+ 17 other calls in file

123
124
125
126
127
128
129
130
131
132
const fitnesses = R.map(R.curry(fitness)(target), population)
const totalFitness = R.sum(fitnesses)
const cumulFitnesses = R.tail(R.scan(R.add, 0, fitnesses))

const r = Math.random() * totalFitness
const [xs, ys] = R.splitWhen(
  ([_, cf]) => cf >= r,
  R.zip(population, cumulFitnesses)
)
const newPopulation = [...R.map(R.head, xs), ...R.map(R.head, R.tail(ys))]
fork icon0
star icon0
watch icon0

+ 2 other calls in file

12
13
14
15
16
17
18
19
20
21
22
 * how it goes.
 */
function application() {
  const lines = data.split('\n')


  const [stackLines, instructionLines] = R.splitWhen(
    line => line.trim().length === 0,
    lines 
  )

fork icon0
star icon0
watch icon0

127
128
129
130
131
132
133
134
135
136
137


// insertIntoArray :: RungSpec -> RungSpecArray -> RungSpecArray
// Returns shallow copy of rungSpecs with newRung inserted, keeping result sorted by dim in descending order
const insertIntoArray = R.curry(
  (newRung, rungSpecs) => R.pipe(
    R.splitWhen(r => r.dim < newRung.dim),
    R.insert(1, newRung),
    R.flatten
  )(rungSpecs)
)
fork icon0
star icon0
watch icon0

24
25
26
27
28
29
30
31
32
33
34
const crabGame = (moves) => {
  let cups = INITIAL_CUPS
  R.times(() => {
    cups = move(cups)
  }, moves)
  const [bottom, [one, ...top]] = R.splitWhen(R.equals(1), cups)
  return R.join("", [...top, ...bottom])
}


const result = crabGame(100)
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)