Skip to content

Commit

Permalink
This is a better name than ExtractorError
Browse files Browse the repository at this point in the history
  • Loading branch information
griotspeak committed Dec 24, 2024
1 parent 6442269 commit e7f4920
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sources/DiscriminatedUnion/DiscriminatedUnion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// prefixed(tupleFrom),
// named(Discriminant),
// named(discriminant),
// named(ExtractorError)
// named(PayloadExtractionError)
)
public macro discriminatedUnion() = #externalMacro(
module: "DiscriminatedUnionMacros",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ extension DiscriminatedUnionMacro: MemberMacro {
try DeclSyntax(validating: $0)
}

let validatedExtractorError = try DeclSyntax(validating: extractorErrorDecl())
let validatedPayloadExtractionError = try DeclSyntax(validating: extractorErrorDecl())

return try [
DeclSyntax(validating: "\(raw: discriminantDecl)"),
validatedPropertyDecl,
validatedExtractorError
validatedPayloadExtractionError
] + validatedExtractors
}

Expand All @@ -73,7 +73,7 @@ extension DiscriminatedUnionMacro: MemberMacro {

static func extractorErrorDecl() -> DeclSyntax {
"""
public enum ExtractorError: Swift.Error {
public enum PayloadExtractionError: Swift.Error {
case invalidExtraction(expected: Discriminant, actual: Discriminant)
}
"""
Expand Down Expand Up @@ -150,7 +150,7 @@ extension DiscriminatedUnionMacro: MemberMacro {
let titleCasedName = "\(caseName.first!.uppercased())\(caseName.dropFirst())"
return """
public func tupleFrom\(raw: titleCasedName)() -> Swift.Result<\(raw: tupleType), ExtractorError> {
public func tupleFrom\(raw: titleCasedName)() -> Swift.Result<\(raw: tupleType), PayloadExtractionError> {
if case .\(raw: caseName)(\(raw: pBindings)) = self {
.success(\(raw: returnValue))
} else {
Expand Down
6 changes: 3 additions & 3 deletions Tests/DiscriminatedUnionTests/DiscriminatedUnionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ enum Pet {
}
}
public enum ExtractorError: Swift.Error {
public enum PayloadExtractionError: Swift.Error {
case invalidExtraction(expected: Discriminant, actual: Discriminant)
}
public func tupleFromCat() -> Swift.Result<Bool, ExtractorError> {
public func tupleFromCat() -> Swift.Result<Bool, PayloadExtractionError> {
if case .cat(let curious) = self {
.success(curious)
} else {
.failure(.invalidExtraction(expected: .cat, actual: self.discriminant))
}
}
public func tupleFromBird() -> Swift.Result<(name: String, Int), ExtractorError> {
public func tupleFromBird() -> Swift.Result<(name: String, Int), PayloadExtractionError> {
if case .bird(let name, let index1) = self {
.success((name, index1))
} else {
Expand Down

0 comments on commit e7f4920

Please sign in to comment.