Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print ALL defined variables/method signatures in Spark Shell - Scala REPL

When I use the spark-shell I end up defining many var, val, and methods. At some point I forget what I have available in my session. How do I print that?

e.g.

val x = 10;
var y = 15;
def myMethod(input: Int): Int = { input * 2 }

// invoke magic print command to obtain something like:
// > val x;
// > var y;
// > myMethod(input: Int): Int;

EDIT (Clarification):

If I type the following:

scala> def foo(x: Int, y: Int): Int = { x * y }
foo: (x: Int, y: Int)Int
scala> def bar(x: Int, y: Int): Int = { x / y }
bar: (x: Int, y: Int)Int

Is there anything that I could type to print only the following for the method defined by me?

foo: (x: Int, y: Int)Int
bar: (x: Int, y: Int)Int
like image 375
Marsellus Wallace Avatar asked Mar 10 '23 05:03

Marsellus Wallace


1 Answers

You can try something similar to this:

$intp.definedTerms
  .map(t => s"${t.toTermName}: ${$intp.typeOfTerm(t.toTermName.toString)}")
  .foreach(println)
like image 196
zero323 Avatar answered Apr 29 '23 19:04

zero323