Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use primary associated type to reduce boilerplate #266

Open
stevapple opened this issue Jun 22, 2022 · 1 comment
Open

Use primary associated type to reduce boilerplate #266

stevapple opened this issue Jun 22, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@stevapple
Copy link
Contributor

After SE-0346 lands in Swift 5.7, it’s possible for us to mark Event and Output as primary associate types for LambdaHandler. This can simplify a demo handler from:

@main
struct MyLambda: LambdaHandler {
    typealias Event = String
    typealias Output = String

    init(context: LambdaInitializationContext) async throws {
        // setup your resources that you want to reuse for every invocation here.
    }

    func handle(_ input: String, context: LambdaContext) async throws -> String {
        // as an example, respond with the input's reversed
        String(input.reversed())
    }
}

into

@main
struct MyLambda: LambdaHandler<String, String> {
    init(context: LambdaInitializationContext) async throws {
        // setup your resources that you want to reuse for every invocation here.
    }

    func handle(_ input: String, context: LambdaContext) async throws -> String {
        // as an example, respond with the input's reversed
        String(input.reversed())
    }
}
@stevapple
Copy link
Contributor Author

Note that the demo doesn’t work at the moment because parameterized protocol support is not fully implemented yet. It is valid and hopefully we could use it starting from 5.7.

@sebsto sebsto added documentation Improvements or additions to documentation enhancement New feature or request labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants