โ† Back

Sift

Swift DSL for building predicates and sort orders from KeyPaths and result builders.

README

๐Ÿงน Sift

Sift is a Swift Domain-Specific Language (DSL) that provides a clean, readable way to construct predicates and sort orders using KeyPaths and Result Builders. Designed for Swift developers, Sift simplifies complex filtering and sorting logic, making it easy to integrate powerful data manipulation in your projects.

โœจ Features

โ€ข	๐Ÿ” Concise Predicate and Sort Descriptions: Easily define predicates and sort orders without verbose syntax.
โ€ข	๐Ÿ› ๏ธ Swift KeyPath Support: Leverages Swift KeyPaths to access properties directly, making code safe and expressive.
โ€ข	๐Ÿš€ Result Builder Integration: Combines the power of Swiftโ€™s Result Builders to enable a readable DSL.
โ€ข	๐Ÿ“ฆ Easy Integration: Available as a Swift Package for seamless integration.

๐Ÿ“ฅ Installation

To integrate Sift into your Swift project, add it as a dependency in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/pauljohanneskraft/Sift", from: "1.0.0")
]

๐Ÿ“ Usage

๐Ÿ”ง Basic Predicate and Sort Order Creation

With Sift, you can create predicates and sort descriptors concisely:

import Sift

struct Item {
    var name: String
    var price: Double
}

let items = [
    Item(name: "Apple", price: 1.0),
    Item(name: "Orange", price: 1.5),
    Item(name: "Banana", price: 0.5)
]

// Applying the filter
let filteredItems = items.filter(by: \.price < 5)

// Defining a sort order
let sortedItems = items.sorted(by: Descending(\.self))

๐Ÿ”„ Advanced Compositions

Combine multiple conditions for complex filters and sort orders:


let sortedComplexItems = items.sortedOrder {
        Reverse {
            \Int.self
        }
        Descending(\Int.self)
    }

๐Ÿ“š Documentation

Further documentation, examples, and advanced usage guides are not yet available.

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for more details.

๐Ÿค Contributing

Contributions are welcome! Please submit a pull request or create an issue for any bugs or feature requests.