//
//  MySortDescriptor.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 26/03/2024.
//

import Foundation

struct MySortDescriptor<Value> {
    var comparator: (Value, Value) -> ComparisonResult
}

extension MySortDescriptor {
    static func keyPath<T: Comparable>(_ keyPath: KeyPath<Value, T>) -> Self {
        Self { rootA, rootB in
            let valueA = rootA[keyPath: keyPath]
            let valueB = rootB[keyPath: keyPath]

            guard valueA != valueB else {
                return .orderedSame
            }

            return valueA < valueB ? .orderedAscending : .orderedDescending
        }
    }
}
