Why is the scala list implementation named :: and not a class name? Is there some special meaning behind that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is to work with pattern matching. You have something called an Infix Operator Patterns where pattern
p op qis equivalent to the constructor or extractor patternop(p, q).So the case class
::defines the constructor::(head, tail). That allows you to match like this:But with the infix operator pattern, you can write the more familiar syntax:
Note that a stackoverflow search on “[scala] infix operator pattern” returns similar questions and additional use cases of the pattern.