alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (null-and-intersect.scala)

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

Java - Scala tags/keywords

bippy, bippy, boppy, boppy, immortal, immortal, immutable, immutable, iterable, map, seq, test, traversable, unit

The Scala null-and-intersect.scala source code

object Test {
  trait Immortal
  class Bippy extends Immutable with Immortal
  class Boppy extends Immutable
  
  def f[T](x: Traversable[T]) = x match {
    case _: Map[_, _]   => 3
    case _: Seq[_]      => 2
    case _: Iterable[_] => 1
    case _              => 4
  }
  def g(x: Bippy) = x match {
    case _: Immutable with Immortal => 1
    case _                          => 2
  }
  def h(x: Immutable) = x match {
    case _: Immortal => 1
    case _           => 2
  }

  def main(args: Array[String]): Unit = {
    println(f(Set(1)))
    println(f(Seq(1)))
    println(f(Map(1 -> 2)))
    println(f(null))
    
    println(g(new Bippy))
    println(g(null))
    
    println(h(new Bippy))
    println(h(new Boppy))
    println(h(null))
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala null-and-intersect.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, alvinalexander.com
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.