Is Array a PartialFunction in Scala?

#1

I see that there is a lift method available for class Array. Which is delegated to lift method of the class PartialFunction. So there must be an implicit class that is able to turn an Array into a PartialFunction? I am not able to find out where it is, though.

#2

Looks like it’s Predef.wrapRefArray which implicitly converts to scala.collection.mutable.WrappedArray which extends AbstractSeq which extends Seq which extends PartialFunction

1 Like
#3

Whoa! how did you figure that you? :smiley:

#4

Actually there are a whole bunch of converters there, depending on the array element type. https://github.com/scala/scala/blob/2.12.x/src/library/scala/Predef.scala#L603-L634

1 Like
#5

I wrote Array().lift in IntelliJ, put the cursor on Array(), and pressed Ctrl-Shift-Q, which shows the implicit conversion in use (or at least its best guess, plus a bunch of other things it’s not sure about). Then Ctrl-H in class WrappedArray shows its type hierarchy, and I selected supertype hierarchy, clicked Expand All, and typed in the tree to find PartialFunction.

Of course it sounds a lot easier to describe it after the fact, there definitely was trial and error involved.

1 Like
#6

Nice :slight_smile: