将List [Tuple2 [A,B]]转换为Tuple2 [Seq [A],Seq [B]] [英] convert List[Tuple2[A,B]] to Tuple2[Seq[A],Seq[B]]

查看:114
本文介绍了将List [Tuple2 [A,B]]转换为Tuple2 [Seq [A],Seq [B]]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

卡在这里,试图将Case类元组的List转换为序列的元组,然后对结果进行多赋值.

Stuck here, trying to convert a List of case class tuples to a tuple of sequences and multi-assign the result.

val items = repo.foo.list // gives me a List[(A,B)]

我可以像这样完成多项任务:

I can pull off multi-assignment like so:

val(a,b) = (items.map(_._1).toSeq, items.map(_._2).toSeq)

但最好遵循以下步骤一步完成:

but it would be nicer to do in 1 step, along the lines of:

val(a,b) = repo.foo.list.map{case(a,b) => (a,b)}

推荐答案

我不确定我是否正确理解了这个问题.也许unzip可以满足您的需求?

I am not sure if I understood the question correctly. Maybe unzip works for what you want?

以下是一些示例的链接: http://daily-scala. blogspot.de/2010/03/unzip.html

Here is a link with some examples: http://daily-scala.blogspot.de/2010/03/unzip.html

这篇关于将List [Tuple2 [A,B]]转换为Tuple2 [Seq [A],Seq [B]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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