Skip to main content
Version: 2.x

Ordering Derivation

Standard Scala library provides a type class called Ordering[A] that allows us to compare values of type A. ZIO Schema provides a method called ordering that generates an Ordering[A] instance for the underlying type described by the schema:

sealed trait Schema[A] {
def ordering: Ordering[A]
}

Here is an example, where it helps us to sort the list of Person:

import zio.schema._

case class Person(name: String, age: Int)

object Person {
implicit val schema: Schema[Person] = DeriveSchema.gen[Person]
}

val sortedList: Seq[Person] =
List(
Person("John", 42),
Person("Jane", 34)
).sorted(Person.schema.ordering)

ZIO Chat

๐ŸŽ‰ Hey there, ZIO aficionado! ๐ŸŽ‰ Step into the ZIO wonderland with me as your guide. Whether you're a functional fanatic or just dipping your toes into the ZIO ecosystem, I'm here to make your journey smooth. Got ZIO questions? I've got answers! Let's navigate the ZIO universe together and unlock its infinite possibilities!