//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2024 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// @_spi(Expression) @available(FoundationPredicate 0.4, *) public struct Expression : Sendable { public let expression : any StandardPredicateExpression public let variable: (repeat PredicateExpressions.Variable) public init(_ builder: (repeat PredicateExpressions.Variable) -> any StandardPredicateExpression) { self.variable = (repeat PredicateExpressions.Variable()) self.expression = builder(repeat each variable) } public func evaluate(_ input: repeat each Input) throws -> Output { try expression.evaluate( .init(repeat (each variable, each input)) ) } } @_spi(Expression) @freestanding(expression) @available(FoundationPredicate 0.4, *) public macro Expression(_ body: (repeat each Input) -> Output) -> Expression = #externalMacro(module: "FoundationMacros", type: "ExpressionMacro")