Skip to content

Instantly share code, notes, and snippets.

@khanlou
Created August 1, 2024 03:32
Show Gist options
  • Save khanlou/eec3a49908ed0c61996bcd4235c1e1a6 to your computer and use it in GitHub Desktop.
Save khanlou/eec3a49908ed0c61996bcd4235c1e1a6 to your computer and use it in GitHub Desktop.
func truesFirst<T>(_ propertyAccessor: @escaping (T) -> Bool) -> (T, T) -> Bool {
{ lhs, rhs in
propertyAccessor(lhs) && !propertyAccessor(rhs)
}
}
func falsesFirst<T>(_ propertyAccessor: @escaping (T) -> Bool) -> (T, T) -> Bool {
{ lhs, rhs in
!propertyAccessor(lhs) && propertyAccessor(rhs)
}
}
cars.sorted(by: truesFirst(\.isManualTransmission))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment