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

Scala example source code file (array-not-seq.scala)

This example Scala source code file (array-not-seq.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

any, any, anyref, array, array, list, list, nil, none, seq, seq, some, test, unit

The Scala array-not-seq.scala source code

object Test {
  def f1(x: Any) = x.isInstanceOf[Seq[_]]
  def f2(x: Any) = x match {
    case _: Seq[_]  => true
    case _          => false
  }

  def f3(x: Any) = x match {
    case _: Array[_]  => true
    case _            => false
  }
  
  def f4(x: Any) = x.isInstanceOf[Traversable[_]]
  
  def f5(x1: Any, x2: Any, x3: AnyRef) = (x1, x2, x3) match {
    case (Some(_: Seq[_]), Nil, _)        => 1
    case (None, List(_: List[_], _), _)   => 2
    case _                                => 3
  }

  def main(args: Array[String]): Unit = {
    // println(f1(Array(1)))
    // println(f2(Array(1)))
    // println(f3(Array(1))
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala array-not-seq.scala source code file:

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.