Any reason why scala does not explicitly support dependent types?

Syntactic convenience aside, the combination of singleton types, path-dependent types and implicit values means that Scala has surprisingly good support for dependent typing, as I’ve tried to demonstrate in shapeless. Scala’s intrinsic support for dependent types is via path-dependent types. These allow a type to depend on a selector path through an object- (ie. value-) … Read more

How can I use map and receive an index as well in Scala?

I believe you’re looking for zipWithIndex? scala> val ls = List(“Mary”, “had”, “a”, “little”, “lamb”) scala> ls.zipWithIndex.foreach{ case (e, i) => println(i+” “+e) } 0 Mary 1 had 2 a 3 little 4 lamb From: http://www.artima.com/forums/flat.jsp?forum=283&thread=243570 You also have variations like: for((e,i) <- List(“Mary”, “had”, “a”, “little”, “lamb”).zipWithIndex) println(i+” “+e) or: List(“Mary”, “had”, “a”, “little”, … Read more

comparing sbt and Gradle [closed]

Note that one key difference between SBT and Gradle is its dependency management: SBT: Ivy, with a a revision which can be given as a fixed one (1.5.2, for instance) or as latest (or dynamic) one. See “Ivy Dependency” That means the “-SNAPSHOT” mechanism support can be problematic, even though Mark Harrah details in this … Read more

Scala how can I count the number of occurrences in a list

A somewhat cleaner version of one of the other answers is: val s = Seq(“apple”, “oranges”, “apple”, “banana”, “apple”, “oranges”, “oranges”) s.groupBy(identity).mapValues(_.size) giving a Map with a count for each item in the original sequence: Map(banana -> 1, oranges -> 3, apple -> 3) The question asks how to find the count of a specific … Read more

What are the relationships between Any, AnyVal, AnyRef, Object and how do they map when used in Java code?

I’ll disagree with Chris’s answer in one regard. The classes Any, AnyRef and AnyVal are classes. But they don’t appear as classes in bytecode, because of intrinsic limitations of the JVM. This arises out of the fact that not everything in Java is an object. In addition to objects, there are primitives. All objects in … Read more

Easy idiomatic way to define Ordering for a simple case class

My personal favorite method is to make use of the provided implicit ordering for Tuples, as it is clear, concise, and correct: case class A(tag: String, load: Int) extends Ordered[A] { // Required as of Scala 2.11 for reasons unknown – the companion to Ordered // should already be in implicit scope import scala.math.Ordered.orderingToOrdered def … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)