blob: d852d940d16890776dbee04e5077c637079a0584 [file] [log] [blame]
// RUN: %target-swift-frontend -typecheck %s
extension Sequence {
func sorted<T: Comparable, K: KeyPath<Element, T>>(by keyPath: K) -> Array<Element> {
self.sorted { $0[keyPath:keyPath] < $1[keyPath:keyPath] }
}
}
struct Foo {
let a: Int
}
func main() {
print([Foo(a: 2), Foo(a:1), Foo(a:4), Foo(a:3)].sorted(by: \Foo.a))
}
main()