0

I tried to create an array in scala.

In scala repl when i put dot and press tab i could see only few function available.

scala> val d = Array(1,2,3,4,5)
d: Array[Int] = Array(1, 2, 3, 4, 5)
scala> d.
apply          asInstanceOf   clone          isInstanceOf   length         toString       update

But i was able to run sum, head ,tail etc on Array although scala repl didn't show them.

I couldn't understand why functions such as head, tail etc were not shown by scala repl.

1
  • 3
    If you press tab again a couple of times it should show them. As Dima explained those methods are not part of Array so they are not immediately shown, if you keep pressing tab the * REPL** searches for more methods. - I any case, it should not affect you that they are not shown, you can still call them. Also, this may be another (good) reason for preferring aList or any other real collection over an Array Commented Mar 6, 2021 at 12:58

1 Answer 1

3

Because Array doesn't actually have those methods. They are defined on either ArrayOps or ArraySeq. There are implicit conversions that allow you invoke those methods directly as if they were defined on array, but what really goes on when you do array.sum is something like ArraySeq.make(array).sum

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.