Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala使用JodaTime定义流_Scala_Implicit - Fatal编程技术网

Scala使用JodaTime定义流

Scala使用JodaTime定义流,scala,implicit,Scala,Implicit,我刚刚开始我的scala之旅。我试图定义一个隐式转换,它可以在一段时间内以这种方式迭代每天: for (day <- firstDay until lastDay) { // a lot of interesting code goes here } 实现until方法的方法是什么?该流是否适用于此?或者应该是迭代器还是Seq?还是别的 谢谢我想你在找这样的东西: implicit class DateTimeWithUntil(from: DateTime) { def unt

我刚刚开始我的scala之旅。我试图定义一个隐式转换,它可以在一段时间内以这种方式迭代每天:

for (day <- firstDay until lastDay) {
  // a lot of interesting code goes here
}
实现until方法的方法是什么?该流是否适用于此?或者应该是迭代器还是Seq?还是别的


谢谢

我想你在找这样的东西:

implicit class DateTimeWithUntil(from: DateTime) {
  def until(to: DateTime): Stream[DateTime] =
    from #:: from.plusDays(1)
}
import org.joda.time._

implicit class DateTimeOps (startDt: DateTime) {
  def until(endDt: DateTime) = for(dayNo <- 0 until Days.daysBetween(startDt, endDt).getDays) yield(startDt.plusDays(dayNo))
}

for(day <- new DateTime() until new DateTime().plusDays(10)) println (day)
import org.joda.time_
隐式类DateTimeOps(startDt:DateTime){

def until(endDt:DateTime)=for(day否您当前的代码对
to
日期没有任何作用-它返回一个无限的
。您必须使其在
to
日期停止。我尝试了以下操作:from#::(if(DateUtils.isSameDay(from.toDate,to.toDate))Stream.empty-els-to(from.plusDays(1)))但是我认为它不能正常工作。顺便说一句,您可能对joda time的scala包装器感兴趣。Repo有非常旧的提交,所以我不想将其作为依赖项导入,但您可以监视到目前为止的实现。