FunctionCallable

@dynamicCallable
public struct FunctionCallable : Sendable

Structure enabling the following syntactic sugar for user functions:

guard case let .int32(sum) = try await user.functions.sum([1, 2, 3, 4, 5]) else {
   return
}

The dynamic member name (sum in the above example) is provided by @dynamicMemberLookup which is directly associated with the function name.

  • The implementation of @dynamicCallable that allows for Future<AnyBSON, Error> callable return.

    let cancellable = user.functions.sum(1, 2, 3, 4, 5)
       .sink(receiveCompletion: { result in
    }, receiveValue: { value in
       // Returned value from function
    })
    

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func dynamicallyCall(withArguments args: [AnyBSON]) -> Future<AnyBSON, Error>
  • The implementation of @dynamicMemberLookup that allows for async await callable return.

    guard case let .int32(sum) = try await user.functions.sum(1, 2, 3, 4, 5) else {
       return
    }
    

    Declaration

    Swift

    public func dynamicallyCall(withArguments args: [AnyBSON]) async throws -> AnyBSON