- b0lt
- Apr 29, 2005
-
|
scalaz owns
code:sealed abstract class ==>>[A, B] {
def \\(other: ==>>[A, B])(implicit o: Order[A]): ==>>[A, B]
}
|
#
¿
Mar 17, 2015 21:21
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 10, 2024 20:48
|
|
- b0lt
- Apr 29, 2005
-
|
+ is indeed a handy operator; you may find however that it is hardly unique to scala.
Is there a butt emoji? It should expand to (_*_) the same way ⇒ does to =>.
|
#
¿
Apr 1, 2015 01:16
|
|
- b0lt
- Apr 29, 2005
-
|
Why isn't ArrayBuffer[String] an Iterable[String]?
Let's say I have an ArrayBuffer like this:
code:val a = ArrayBuffer[String]("AAA", "BBB", "CCC")
// I can make a string of the elements with some separator like this:
a.mkString(", ") // "AAA, BBB, CCC"
Coming from C# I'm used to being able to do string.Join(", ", a) which takes an IEnumerable<String>. If I pass a List<String> it works because that's an IEnumerable<String>.
In Scala I have to import asJavaIterable to get an implicit conversion from ArrayBuffer[String] to Iterable[String] so that the same thing works:
code:import scala.collection.JavaConversions.asJavaIterable
String.join(", ", a)
Is this the only way to get this to work (for this overload of join)? Why was it built this way? Why couldn't ArrayBuffer[String] implement Iterable? Going through the inheritance heirarchy I see the Iterable trait in there, which after some confusion I realized is not the same as the Iterable interface.
I can also get it to work doing this:
code:String.join(", ", a: _*)
...which converts a to a CharSequence... varargs argument for the other overload of join. What is that : _* doing? Is that an operator?
java.lang.Iterable is not the same as scala.collection.Iterable. Scala's Iterable's iterator method collides with the Java one, so classes can only implement one of them.
:_* expands the argument to fill the rest, either by converting to an Array for a variadic function, or by unpacking a tuple.
|
#
¿
Aug 6, 2015 03:12
|
|