Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try tu use more general types in match phrase, like <code>GenTraversable</code> to witch exists implicit conversion.</p> <pre class="lang-scala prettyprint-override"><code>import scala.collection.GenTraversable def rprint[T](a: T, indent: Int = 0): Unit = a match { case x: String =&gt; println(" "*indent + '"' + x + '"') case x: GenTraversable[_] =&gt; println(" "*indent + (x.stringPrefix)) x foreach (rprint(_, indent+2)) case x: Array[_] =&gt; println(" "*indent + (a.getClass.getSimpleName)) x foreach (rprint(_, indent+2)) case x =&gt; println(" "*indent + x) } rprint(Map(1-&gt;"one",2-&gt;"two")) rprint(List("one", "two")) //I don't know why this type is printed weird: $colon$colon rprint(Array(1,2)) //This prints less weird: int[] </code></pre> <p>You can add more cases for specific missing types (like tuples)</p> <p>I can't figure what is the problem with printing some type names (like <code>List</code> and <code>Array</code> - see the example after the function definition). Both <code>a.getClass.getSimpleName</code> and <code>a.ToString</code> returns wired string</p> <p>I've also try to connect type <code>Array</code> and <code>GenTraversable</code> - because there is implicit conversion from <code>Array</code> to <code>WrapperArray &lt;: GenTraversable</code>. <br /> The solution below doesn't satisfy as it prints "WrappedArray" instead "Array", when we call the function with <code>Array</code> instance</p> <pre><code>case x: Array[_] =&gt; rprint(x:GenTraversable[_]) </code></pre> <p>Edit:<br /> I've changed name extractor for GenTraversable to <code>a.stringPrefix</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload