简体   繁体   中英

What's the meaning of #:: in Scala?

What is the meaning of x#::xs in Scala?

for example

 case x #:: xs => {

In this case x was a Stream but I suppose that the same syntax is valid also for list ecc...

It's an extractor for pattern matching streams . This is not valid for Lists. The lists have :: (note there is no # in the list).

The meaning of the case x #:: xs => is that when the pattern is matched, the x will contain the head of the stream, and the xs will contain the rest of the stream (tail).

Check the stream documentation for examples on how to define streams.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM