Hey @NoahKamara, thanks for sharing! This is super neat and I'm happy to see some new thoughts around potential APIs for Predicate!
In addition to your library, I wanted to share that Foundation now has support for this as well as of macOS 14.4 / iOS 17.4. Your example above can be written with the new Foundation support via the following:
let notTooShort = #Predicate<Book> { $0.pages > 50 }
let notTooLong = #Predicate<Book> { $0.pages <= 350 }
let titleFilter = #Predicate<Book> { $0.title.contains("Swift") }
let filter = #Predicate<Book> {
(notTooShort.evaluate($0) && notTooLong.evaluate($0)) || titleFilter.evaluate($0)
}
This capability might not be quite as easy to discover as a function like conjunction/disjunction on Predicate itself like you have in your library, but should support compound predicates as well as more complex constructions beyond just conjunctions/disjunctions. Hope this helps a bit in your Predicate endeavors! You can see more details about the Foundation change in this PR on the swift-foundation repo.