Am 2017-01-26 12:49, schrieb Jonathan Hull via swift-evolution:
I had a realization a few weeks ago that regexes with capture groups
actually correspond to a type, where successive capture groups form a
tuple and recursive ones form arrays of the capture groups they
recurse (and ‘?’ conveniently forms an optional). For example the
type for the regex above would be (Int,String). Those types could be
pretty hairy for complex regexes though.
let (id,name) = /(\d+): (\w+)/
Well, the regex would have a type of its own, but it would probably have
a
generic Result parameter, which would include your `(Int,String)`.
You only get your (id,name) pair when match some input against that
regex.
E.g. something like:
let r: Regex<(Int, String)> = /(\d+): (\w+)/
switch input {
case r(let id, let name): print("\(id): \(name)")
}
--
Martin
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution