How to use the splitWhenever function from ramda

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

78
79
80
81
82
83
84
85
86
87
88
89
    R.range(0,R.length(monkeys))
  ))


const monkeys1 = R.compose(
  R.map(parseMonkey(true)),
  R.splitWhenever(R.isEmpty)
)(content)


const monkeys2 = R.compose(
  R.map(parseMonkey(false)),
fork icon0
star icon0
watch icon0

+ 7 other calls in file

5
6
7
8
9
10
11
12
13
14
15
const elves = R.pipe(
  R.partialRight(fs.readFileSync, ["utf8"]),
  R.trim,
  R.split('\n'),
  R.map(parseInt),
  R.splitWhenever(R.equals(NaN)),
)(DATA);


// part 1
R.pipe(
fork icon0
star icon0
watch icon0

52
53
54
55
56
57
58
59
60
61
const lines = data.split('\n')

// A lot of focus on parsing slightly bad input formats
// in this year's puzzles...
// Let's split the list into paragraphs for each monkey
const monkeyDataList = R.splitWhenever(line => line.length < 1, lines)

// The first line that identifies the monkey is unimportant
// so let's just throw it away
const monkeyList = monkeyDataList.map(parseMonkeyData)
fork icon0
star icon0
watch icon0

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


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


function parse(lines) {
    return R.splitWhenever(x => x.length < 1, lines).map(x => x.map(y => JSON.parse(y)));
}


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

fork icon0
star icon0
watch icon0

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


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


function parse(lines) {
    const s1 =  R.splitWhenever(R.isEmpty, lines);
    const s2 = s1.map(x => ({
        items: x[1].split(': ')[1].split(', ').map(Number),
        op: R.takeLast(2, x[2].split(' ')),
        test: Number(R.last(x[3].split(' '))),
fork icon0
star icon0
watch icon0

10
11
12
13
14
15
16
17
18
19
20
21
22
function parse(lines) {
    const step1 = R.flatten(lines.map(x => R.startsWith('$', x) ? ['$', R.tail(x.split(' ')).join(' ')] : x));


    U.log('step 1', step1);


    const step2 = R.splitWhenever(R.startsWith('$'), step1);
    
    U.log('step 2', step2);


    return step2.map(c => {
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)