| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TimeInstances0.scala)

This example Scala source code file (TimeInstances0.scala) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

dayofweek, enum, int, order, timeinstances0

The TimeInstances0.scala Scala example source code

package scalaz

import java.time._

trait TimeInstances0 {

  private[this] def orderFromInt[A](f: (A, A) => Int): Order[A] = new Order[A] {
    def order(x: A, y: A) = Ordering.fromInt(f(x, y))

  implicit val instantInstance: Order[Instant] = orderFromInt[Instant](_ compareTo _)
  implicit val localDateTimeInstance: Order[LocalDateTime] = orderFromInt[LocalDateTime](_ compareTo _)
  implicit val offsetDateTimeInstance: Order[OffsetDateTime] = orderFromInt[OffsetDateTime](_ compareTo _)
  implicit val offsetTimeInstance: Order[OffsetTime] = orderFromInt[OffsetTime](_ compareTo _)
  implicit val zonedDateTime: Order[ZonedDateTime] = orderFromInt[ZonedDateTime](_ compareTo _)
  implicit val zoneOffsetInstance: Order[ZoneOffset] = orderFromInt[ZoneOffset](_ compareTo _)

  implicit val dayOfWeekInstance: Enum[DayOfWeek] = new Enum[DayOfWeek] {
    override val max = Some(DayOfWeek.SUNDAY)
    override val min = Some(DayOfWeek.MONDAY)
    override def pred(a: DayOfWeek) = a.minus(1)
    override def succ(a: DayOfWeek) =
    override def order(x: DayOfWeek, y: DayOfWeek) =
      Ordering.fromInt(x compareTo y)

Other Scala examples (source code examples)

Here is a short list of links related to this Scala TimeInstances0.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.