Swift: How I can partially apply generic function?

Viewed 56

i have some generic function, and i need to get a link to the generic function with a specific generic type.

// my generic function
func messageResult<M: SwiftProtobuf.Message>(_ dto: M?) {
    result(try? dto?.serializedData())
}

// then i try get link to the function with a specific generic type 
// but i throw error
let dtoResult = messageResult<Dto.OpenResult>

error message: '>' is not a postfix unary operator

ide highlighted: let dtoResult = messageResult<Dto.OpenResult>

how i can write it correctlly?

1 Answers

You can specify the generic argument by type annotating dtoResult

let dtoResult: (Dto.OpenResult) -> () = messageResult
Related