Skip to content

Instantly share code, notes, and snippets.

@hugobenichi
Created July 31, 2013 02:52
Show Gist options
  • Save hugobenichi/6118931 to your computer and use it in GitHub Desktop.
Save hugobenichi/6118931 to your computer and use it in GitHub Desktop.
checking if Seq() will match any empty sequence-like object or not
Compiled from "SeqMatch.scala"
public final class SeqMatch$ {
public static final SeqMatch$ MODULE$;
public static {};
Code:
0: new #2 // class SeqMatch$
3: invokespecial #12 // Method "<init>":()V
6: return
public <T extends java/lang/Object> void check(scala.collection.Seq<T>);
Code:
0: aload_1
1: astore_2
2: getstatic #19 // Field scala/collection/Seq$.MODULE$:Lscala/collection/Seq$;
5: aload_2
6: invokevirtual #23 // Method scala/collection/Seq$.unapplySeq:(Lscala/collection/Seq;)Lscala/Some;
9: astore_3
10: aload_3
11: invokevirtual #29 // Method scala/Option.isEmpty:()Z
14: ifne 57
17: aload_3
18: invokevirtual #33 // Method scala/Option.get:()Ljava/lang/Object;
21: ifnull 57
24: aload_3
25: invokevirtual #33 // Method scala/Option.get:()Ljava/lang/Object;
28: checkcast #35 // class scala/collection/SeqLike
31: iconst_0
32: invokeinterface #39, 2 // InterfaceMethod scala/collection/SeqLike.lengthCompare:(I)I
37: iconst_0
38: if_icmpne 57
41: getstatic #44 // Field scala/Predef$.MODULE$:Lscala/Predef$;
44: ldc #46 // String foo
46: invokevirtual #50 // Method scala/Predef$.println:(Ljava/lang/Object;)V
49: getstatic #56 // Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
52: astore 4
54: goto 70
57: getstatic #44 // Field scala/Predef$.MODULE$:Lscala/Predef$;
60: ldc #58 // String bar
62: invokevirtual #50 // Method scala/Predef$.println:(Ljava/lang/Object;)V
65: getstatic #56 // Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
68: astore 4
70: return
}
object SeqMatch {
def check[T](s: Seq[T]): Unit = s match {
case Seq() => println("foo")
case _ => println("bar")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment