FunctionCallable

@dynamicCallable
public struct FunctionCallable

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, watchOS 6.0, iOS 13.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOS 13.0, *)
    public func dynamicallyCall(withArguments args: [[AnyBSON]]) -> Future<AnyBSON, Error>