- Starting with a lineSequence
- I'd like to test if a Regex matches, and if so, get the first match
- Furthermore, I'd like to return a capturing group from that Regex match
If I didn't care, I'd do a "first" on the lineSequence, and if it existed, re-run the regex.
val possibleMatch = input.lineSequence().first { myRegex.matches(it) }
... but I want to be kotlin-cool and not have to re-run the regex. Should I use a map to a MatchGroup and filter out nulls? Feels more verbose than it could be...
input.lineSequence()
.mapNotNull { myRegex.find(it) }
.map { it.groupValues[1] }
.first()