Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Last active June 11, 2026 20:19
Show Gist options
  • Select an option

  • Save natecook1000/6aab5c755a350f356b0d8c48c551914c to your computer and use it in GitHub Desktop.

Select an option

Save natecook1000/6aab5c755a350f356b0d8c48c551914c to your computer and use it in GitHub Desktop.
/// A guaranteed-sendable regex type.
struct SendableRegex<Output>: RegexComponent, @unchecked Sendable {
let regex: Regex<Output>
init?(_ re: some RegexComponent<Output>) {
if nil == re.regex._literalPattern { return nil }
self.regex = re.regex
}
}
// Usage:
import RegexBuilder
let simpleRegex = #/a+b*c/#
let complexRegex = Regex {
OneOrMore { "a" }
ZeroOrMore { "b" }
TryCapture {
OneOrMore(.digit)
} transform: {
Int($0)
}
}
let sendableRegex = SendableRegex(simpleRegex) // ok
let nonSendableRegex = SendableRegex(complexRegex) // nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment