Scala zip列表到元组 [英] scala zip list to tuple

查看:54
本文介绍了Scala zip列表到元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与JodaTime一起工作,尝试将List [LocalDate]转换为Tuple2 [JodaTime,JodaTime],以便我可以像这样进行多重协助:

Working with JodaTime, trying to convert a List[LocalDate] to Tuple2[JodaTime, JodaTime] so I can do multi-assigment like so:

val(expire, now) = 
  List(row.expireDate, new JodaDate) zip (_.toDateTimeAtStartOfDay.getMillis)

当然不会编译.有没有类似的简洁方法可以完成上述操作?我知道我可以手动完成:

which of course does not compile. Is there a similarly concise way to do the above? I know I can just do it manually:

val(expire, now) = 
  (row.expireDate.toDateTimeAtStartOfDay.getMillis, 
   new JodaDate().toDateTimeAtStartOfDay.getMillis)

但这有点难看

推荐答案

val Seq(expire, now) = 
  Seq(row.expireDate, new JodaDate).map(_.toDateTimeAtStartOfDay.getMillis)

这篇关于Scala zip列表到元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆