regexp static method

Conveyor<From<String>, String> regexp(
  1. String regexpSource, {
  2. int group = 0,
})

Implementation

static Conveyor<From<String>, String> regexp(String regexpSource, {int group = 0}) {
  final regexp = new RegExp(regexpSource);
  final pipe = Pipe.consume<String, String>((s) {
    final matches = ilist(regexp.allMatches(s)).filter((m) => m.groupCount >= group);
    return matches.foldRight(Pipe.halt(), (match, acc) => Pipe.produce(match.group(group) ?? "", acc));
  });
  return pipe.repeatUntilExhausted();
}