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

Scala example source code file (Depth.scala)

This example Scala source code file (Depth.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

anydepth, anyval, depth, int, ordered, zero

The Depth.scala Scala example source code

package scala
package reflect
package internal

import Depth._

final class Depth private (val depth: Int) extends AnyVal with Ordered[Depth] {
  def max(that: Depth): Depth   = if (this < that) that else this
  def decr(n: Int): Depth       = if (isAnyDepth) this else Depth(depth - n)
  def incr(n: Int): Depth       = if (isAnyDepth) this else Depth(depth + n)
  def decr: Depth               = decr(1)
  def incr: Depth               = incr(1)

  def isNegative = depth < 0
  def isZero     = depth == 0
  def isAnyDepth = this == AnyDepth

  def compare(that: Depth): Int = if (depth < that.depth) -1 else if (this == that) 0 else 1
  override def toString = s"Depth($depth)"

object Depth {
  // A don't care value for the depth parameter in lubs/glbs and related operations.
  final val AnyDepth = new Depth(Int.MinValue)
  final val Zero     = new Depth(0)

  @inline final def apply(depth: Int): Depth = if (depth < 0) AnyDepth else new Depth(depth)

Other Scala source code examples

Here is a short list of links related to this Scala Depth.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.