These are chat archives for ramda/ramda

9th
May 2018
Pedr Browne
@Undistraction
May 09 2018 15:52

Does Ramda offer a way around using a while loop in this instance:

let matchedValues =  []
let matchedValue

while (matchedValue = regExp.exec(value)) {
   matchedValues.push(matchedValue[1]);
}

There doesn't seem to be a looping construct which doesn't require the use of a list, where here I need to loop until a function returns a nil value.

It's part of a function that transforms and replaces the values of multiple capture groups: REPL

I'd love to know if there is a better way.

Mike Lambert
@lax4mike
May 09 2018 15:53
Mike Lambert
@lax4mike
May 09 2018 15:59
i'm confused why that needs to be in a while loop?
Pedr Browne
@Undistraction
May 09 2018 16:03
regExp.exec(value) needs to be called repeatedly. It will either return a match (the capture group I'm interested in is at idx 1), or nil when there are no more matches. I need a list containing these matches.
Mike Lambert
@lax4mike
May 09 2018 16:08
your regex has /g so it will get all matches the first time, right?
Pedr Browne
@Undistraction
May 09 2018 16:11
Unfortunately exec doesn't seem to work like that when using capture groups.
If I wasn't using capture groups then yes - I could just use the global flag, but with capture groups, this is the only way.
Mike Lambert
@lax4mike
May 09 2018 16:12
very weird, i've never seen that before
Pedr Browne
@Undistraction
May 09 2018 16:12
I'd never come across it until now either.
Mike Lambert
@lax4mike
May 09 2018 16:13
If the match succeeds, the exec() method returns an array and updates properties of the regular expression object.
so exec is not pure
i wonder if you want to use match instead?
If the string matches the expression, it will return an Array containing the entire matched string as the first element, followed by any results captured in parentheses. If there were no matches, null is returned.
Pedr Browne
@Undistraction
May 09 2018 16:22
I think that works the same - if you aren't using capture groups you get an array of matches, but if you are, you don't.
Pedr Browne
@Undistraction
May 09 2018 16:29
@lax4mike Thanks though, unfold has certainly helped clean it up: REPL
Nate Abele
@nateabele
May 09 2018 19:13
Hey y'all, anybody here working with TypeScript?