Jakub Gwóźdź
11/30/2022, 2:01 PMfun <R> String.parseRecords(regex: Regex, op: (MatchResult) -> R): Sequence<R> =
lineSequence().filterNot(String::isBlank)
.map { regex.matchEntire(it) ?: error("WTF `$it`") }
.map(op)
That works just fine.
How would it look like if I want to make parameters optional (with some default mapping)? I can use regex: Regex = "(.*)"
but the op: (MatchResult) -> R = { it.destructured.component1().toInt()}
is a big no-no, because of Type mismatch: inferred type is Int but R was expected.
Is it even possible to add default parameter values for generic functions?Sam
11/30/2022, 2:03 PMJakub Gwóźdź
11/30/2022, 2:06 PM