How to use the match function from ramda

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

127
128
129
130
131
132
133
134
135
136
return R.pipe(
  () => this.shell("dumpsys activity activities").toString(),
  R.split("\n"),
  R.map(R.pipe(
    R.trim,
    R.match(/Run #\d+: ActivityRecord{\w+ \w+ ([\w\.\/]+)/),
    it => it ? it[1] : null,
  )),
  R.filter(R.identity),
)();
fork icon1
star icon1
watch icon0

2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
 * @param {String} str The string to match against
 * @return {Array} The list of matches or empty array.
 * @see R.test
 * @example
 *
 *      R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
 *      R.match(/a/, 'b'); //=> []
 *      R.match(/a/, null); //=> TypeError: null does not have a method named "match"
 */
var match = _curry2(function match(rx, str) {
fork icon0
star icon0
watch icon0

+ 71 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14
const input = fs.readFileSync('inputs/day02.input', 'utf8').trim();


const pwPolicies = R.compose(
    R.map(R.o(
        R.slice(1, 5),
        R.match(/(\d+)-(\d+) ([a-z]): ([a-z]+)/))),
    R.split('\n'))(input);


const isValidPart1 = ([low, high, lett, pw]) => {
  // example p = ['1', '3', 'a', 'abcde']
fork icon0
star icon0
watch icon0

+ 2 other calls in file

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


const targetArea = R.compose(
    ([x1, x2, y1, y2]) => [[x1, y1], [x2, y2]],
    R.map(parseInt),
    R.slice(1, 5),
    R.match(/target area: x=(-?\d+)\.\.(-?\d+), y=(-?\d+)\.\.(-?\d+)/))(input);


const isInArea = ([[x1, y1], [x2, y2]], [x, y]) =>
  x1 <= x && x <= x2 && y1 <= y && y <= y2;
const isRightOrBelow = ([[, y1], [x2]], [x, y]) => x2 < x || y < y1;
fork icon0
star icon0
watch icon0

27
28
29
30
31
32
33
34
35
36
    // remove the trailing ']'
    rest = R.drop(1, rest);
    return [[left, right], rest];
  } else {
    // or the snail number is just a plain old integer
    const [, num, rest] = R.match(/^(\d+)(.*)/, s);
    return [parseInt(num), rest];
  }
};

fork icon0
star icon0
watch icon0

+ 3 other calls in file

9
10
11
12
13
14
15
16
17
18
19
20


const lines = R.compose(
    R.map(R.compose(
        R.map(parseInt),
        R.slice(1, 5),
        R.match(/(\d+),(\d+) -> (\d+),(\d+)/))),
    R.split('\n'))(input);


const isGridLine = (l) => l[0] === l[2] || l[1] === l[3];
const addBoards = R.mergeDeepWith(R.add);
fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
// Just force rest to be lowercase lol
const capitalize = str =>
  [str.charAt(0).toUpperCase(), str.slice(1).toLowerCase()].join('');

const tokenizeCamelCase = R.pipe(
  R.match(/(^[a-z]+|[A-Z][a-z]+)/g),
  R.map(R.toLower),
);

const tokenizeKebabCase = R.pipe(R.split('-'), R.map(R.toLower));
fork icon0
star icon0
watch icon1

Other functions in ramda

Sorted by popularity

function icon

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