Curycu
Curycu

Reputation: 1605

Range.Partial[Double, NumericRange[Double]] Implicit conversion

I have a question about implicit conversion...

1 to 4: Range[Int] -> Queue[Int] conversion works nicely

but 1.0 to 4.0 -> Queue[Double] doesn't works...

what's the problem with my code below?

=========================================

import scala.collection.immutable._

sealed trait XS[A]{
  def print: Unit = this match {
    case RXS(q) => println(q)
    case LXS(msg) => println(msg)
  }
}

case class RXS[A](q: Queue[A]) extends XS[A]
case class LXS[A](msg: String) extends XS[A]

object XS {

  implicit def seqToQueue[A](seq: Seq[A]): Queue[A] = {
    seq.foldRight(Queue[A]())((a, acc) => a +: acc)
  }

  def apply[A](seq: Seq[A]): XS[A] = {
    RXS(seq)
  }
}

object XSTest extends App {

  val ran = 1 to 9 //Range
  val ob = XS(ran)
  ob.print

  /*val ran2 = 1.0 to 9.0 //Range.Partial[Double, NumericRange[Double]]
  val ob2 = XS(ran2)
  ob2.print*/
}

Upvotes: 1

Views: 273

Answers (1)

Odomontois
Odomontois

Reputation: 16328

Unfortunately 1.0 to 9.0 does not yield subtype of Seq[Double] It's Range.Partial which is expecting additional step argument to be fully specified.

Try to use

XS(1.0 to 9.0 by 1.0)  

Upvotes: 8

Related Questions