Last active
August 18, 2022 08:02
-
-
Save YanSte/1a418c04f6376811cca1b5f3b6f28cbf to your computer and use it in GitHub Desktop.
Predicate, A definition of logical conditions for constraining a search for a fetch or for in-memory filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// A definition of logical conditions for constraining a search for a fetch or for in-memory filtering. | |
/// More info [here](https://www.swiftbysundell.com/articles/predicates-in-swift/) | |
/// | |
/// Sample: | |
/// | |
/// func myMethod(predicate: Predicate<MyObject>) -> Bool { | |
/// objects.contains { predicate(obj) } | |
/// } | |
/// | |
/// let result = myMethod { $0.id == myIdDefined } | |
/// | |
public struct Predicate<Target> { | |
public var matches: (Target) -> Bool | |
public init(matcher: @escaping (Target) -> Bool) { | |
self.matches = matcher | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment