Skip to content

Use primary associated type to reduce boilerplate #266

Closed
@stevapple

Description

@stevapple

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())
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/documentationImprovements or additions to documentation.kind/enhancementImprovements to existing feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions