I study Scala and play with the object unapply with the matching. I know that if the name ends with ":", then it becomes the correct associative. However, there seem to be some weird naming restrictions
eg. They are wrong
object cons: { def unapply(value: String): Option[(Char, List[Char])] = ??? } object :_cons_: { def unapply(value: String): Option[(Char, List[Char])] = ??? }
They are valid
object cons_: { def unapply(value: String): Option[(Char, List[Char])] = ??? } object >>: { def unapply(value: String): Option[(Char, List[Char])] = ??? }
Thus, there is some kind of weirdness in mixing alphanumeric characters and characters in identifiers.
So basically, I want to have a descriptive name, i.e. "cons" and still have the correct associativity. Also, I would like my operator to be symmetrical for aesthetic reasons :-), so I don't like cons_:
Is there a way to do something related right without using a colon? Or any other suggestions to achieve this?
:_cons_: seems closest, but for some reason, the identifier cannot begin with ':' and have alphanumeric characters
source share