In "S-99: Ninety-Nine Scala Problems" they use --
on a List
in graph's equals
method. The problem is, that in Scala I use (2.10.2), the --
operator isn't present (or I'm missing some import).
scala> List(1) -- List(1) <console>:8: error: value -- is not a member of List[Int] List(1) -- List(1) ^
Expected result is empty list.
In older versions of Scala it was working fine (according to this post).
Is there a subtract operator for List
s in Scala's standard library or do I need to cook one myself?
The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand.
In Scala, you can check if two operands are equal ( == ) or not ( != ) and it returns true if the condition is met, false if not ( else ). By itself, ! is called the Logical NOT Operator.
Specific to Scala, a list is a collection which contains immutable data, which means that once the list is created, then it can not be altered. In Scala, the list represents a linked list. In a Scala list, each element need not be of the same data type.
In general: :: - adds an element at the beginning of a list and returns a list with the added element. ::: - concatenates two lists and returns the concatenated list.
scala> List(1,2,3,4) filterNot List(1,2).contains res2: List[Int] = List(3, 4)
or
scala> List(1,2,3,4) diff List(1,2) res3: List[Int] = List(3, 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With