Created
January 18, 2022 03:14
-
-
Save JadenGeller/628d49b5efb5f9f0256301465c118aab to your computer and use it in GitHub Desktop.
ResultBuilder is a free @resultBuilder (as in https://wiki.haskell.org/Free_structure)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@resultBuilder | |
enum ResultBuilder<Expression> { | |
case block([Self]) | |
static func buildBlock(_ components: Self...) -> Self { | |
.block(components) | |
} | |
case expression(Expression) | |
static func buildExpression(_ expression: Expression) -> Self { | |
.expression(expression) | |
} | |
indirect case optional(Self?) | |
static func buildOptional(_ component: Self?) -> Self { | |
.optional(component) | |
} | |
indirect case either(first: Self) | |
static func buildEither(first component: Self) -> Self { | |
.either(first: component) | |
} | |
indirect case either(second: Self) | |
static func buildEither(second component: Self) -> Self { | |
.either(second: component) | |
} | |
case array([Self]) | |
static func buildArray(_ components: [Self]) -> Self { | |
.array(components) | |
} | |
indirect case limitedAvailability(Self) | |
static func buildLimitedAvailability(_ component: Self) -> Self { | |
.limitedAvailability(component) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment