Scala objects are masked as methods versus the actual method (Stream.cons)

I am looking at the Scala Stream API, and I noticed that Stream.cons is implemented as an embedded object. What advantage does this have for implementing it as a function? Under what circumstances should you consider using this technique?

Greetings.

+4
source share
1 answer

It defines unapply as an object in addition to apply , which allows you to map a template to it.

+6
source

Source: https://habr.com/ru/post/1499382/


All Articles