CompoundPredicate

0.1.0

A library for combining swift predicates
NoahKamara/CompoundPredicate

What's New

v0.1.0

2024-03-11T00:03:03Z

Build & Test

CompoundPredicate

CompoundPredicate aims to improve the Predicate system to enable combining multiple predicates after constructing them:

let notTooShort = #Predicate<Book> {
    $0.pages > 50
}

let notTooLong = #Predicate<Book> {
    $0.pages <= 350
}

let lengthFilter = [notTooShort, notTooShort].conjunction()

// Match Books that are just the right length
let titleFilter = #Predicate<Book> {
    $0.title.contains("Swift")
}

// Match Books that contain "Swift" in the title or
// are just the right length
let filter = [lengthFilter, titleFilter].disjunction()

Documentation

The documentation is available here and as Docc archive you can view using Xcode

Implementation Progress

  • Arithmetic (+, -, *, /, %)

    • +, -, * PredicateExpressions.Arithmetic
    • / PredicateExpressions.FloatDivision
    • / PredicateExpressions.IntDivision
    • % PredicateExpressions.IntRemainder
  • Unary minus - PredicateExpressions.UnaryMinus

  • Range (..., ..<)

    • ... PredicateExpressions.ClosedRange
    • ..< PredicateExpressions.Range
    • x..<z).contains(y) PredicateExpressions.RangeExpressionContains
  • Comparison (<, <=, >, >=, ==, !=)

    • <, <=, >, >= PredicateExpressions.Comparison
    • == PredicateExpressions.Equal
    • != PredicateExpressions.NotEqual
  • Conditionals & Ternary (?:) PredicateExpressions.Conditional

  • Boolean logic (&&, ||, !)

    • && PredicateExpressions.Conjunction
    • || PredicateExpressions.Disjunction
    • ! PredicateExpressions.Negation
  • Swift optionals (?, ??, !, flatMap(_:), if-let expressions)

    • ?, flatMap(_:) PredicateExpressions.OptionalFlatMap
    • ??, if-let PredicateExpressions.NilCoalesce
  • Types (as, as?, as!, is)

    • as? PredicateExpressions.ConditionalCast
    • as, as! PredicateExpressions.ForceCast
  • Sequence operations (allSatisfy(), filter(), contains(), contains(where:), starts(with:), max(), min())

    • allSatisfy() PredicateExpressions.SequenceAllSatisfy
    • filter() PredicateExpressions.Filter [completion:: 2024-03-10]
    • contains() PredicateExpressions.SequenceContains [completion:: 2024-03-10]
    • contains(where:) PredicateExpressions.SequenceContainsWhere
    • starts(with:) PredicateExpressions.SequenceStartsWith
    • min() PredicateExpressions.SequenceMinimum [completion:: 2024-03-10]
    • max() PredicateExpressions.SequenceMaximum
  • Subscript and member access ([], .)

    • [0,1][0] PredicateExpressions.CollectionIndexSubscript
    • ["a": "b"]["a"] PredicateExpressions.DictionaryKeySubscript
    • ["a": "b"]["a", defaultValue: "b"] PredicateExpressions.DictionaryKeyDefaultValueSubscript
    • obj.someKey PredicateExpressions.KeyPath
  • String comparisons

    • contains(_:) PredicateExpressions.CollectionContainsCollection
    • localizedStandardContains(_:) PredicateExpressions.StringLocalizedStandardContains
    • caseInsensitiveCompare(_:) PredicateExpressions.StringCaseInsensitiveCompare
    • localizedCompare(_:) PredicateExpressions.StringLocalizedCompare

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun Dec 08 2024 09:43:32 GMT-1000 (Hawaii-Aleutian Standard Time)