Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
b0lt
Apr 29, 2005
scalaz owns
code:
sealed abstract class ==>>[A, B] {
    def \\(other: ==>>[A, B])(implicit o: Order[A]): ==>>[A, B]
}

Adbot
ADBOT LOVES YOU

b0lt
Apr 29, 2005

Steve French posted:

+ 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 =>.

b0lt
Apr 29, 2005

Cryolite posted:

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.

  • Locked thread