scala - 带有前缀的scala组合
问题描述
在scala中生成带有前缀的组合的优雅方法是什么?
"""
((pre_first, pre_second),
(pre_first, pre_second, thing1),
(pre_first, pre_second, thing2),
(pre_first, pre_second, thing3),
(pre_first, pre_second, thing1, thing2),
(pre_first, pre_second, thing1, thing3),
(pre_first, pre_second, thing2, thing3))
""".stripMargin
val prefixes = Seq("pre_first", "pre_second")
val things = Seq("thing1", "thing2", "thing3")
解决方案
(0 to things.size).flatMap(i=>things.combinations(i)).map(prefixes ++ _)
推荐阅读
- python - PyCharm 打开时运行 python 文件
- batch-file - 我已将脚本添加到正文中。每当我在 CMD 中运行所述脚本时,它都会关闭窗口。为什么
- flutter - 有没有办法迭代未来
- 飘飘然
- javascript - 难道我们看不到内置的构造函数,因为它们是用不同的语言编写的吗?
- javascript - 在 pagination.js 中使用 POST 请求
- image - Flutter image_picker 不适用于flutter_plugin_android_lifecycle 问题
- kotlin - if 条件的函数式表达方式
- go - Go 编译器在 x0 中产生奇怪的负载
- java - 我正在尝试使用 JDA(Discord 开发)创建票务系统;变量问题
- ssis - 将月份数字(日期时间或 4 字节整数)转换为月份名称(字符串)SSIS