gpt4 book ai didi

scala - 代码格式:如何在理解中对齐<-?

转载 作者:行者123 更新时间:2023-12-02 07:20:28 24 4
gpt4 key购买 nike

我有这样的for comprehension:

 private[helper] def myMethod(name: String, index: Long) = {
for {
result1 <- httpUtilities.getLowIndexes(index)
result2 <- myFacade.queryMaterial(result1)
result3 <- httpUtilities.someMethod(result2)
} yield result3
}

我想要的是在列中对齐特殊字符 <-,以便将上面的代码转换为:
private[helper] def myMethod(name: String, index: Long) = {
for {
result1 <- httpUtilities.getLowIndexes(index)
result2 <- myFacade.queryMaterial(result1)
result3 <- httpUtilities.someMethod(result2)
} yield result3
}

我可以在设置->代码样式-> Scala =>包装和花括号->'match'和'case'语句->在Intellij中的'case'列中对齐来对区分大小写的语句执行相同的操作 <-中的 for-comprehension字符。

最佳答案

Scalafmt可以完全做到这一点,它可以作为IDEA plugin来使用,也可以通过许多其他方式打包。

您想使用align=more功能as documented here。该文档显示了以下对齐示例:

val x  = 2 // true for assignment
val xx = 22

case object B extends A // false for `extends`
case object BB extends A

q -> 22 // true for various infix operators
qq -> 3 // and also comments!

for {
x <- List(1) // true for alignment enumerator
yy <- List(2)
} yield x ** xx

x match { // true for multiple tokens across multiple lines
case 1 => 1 -> 2 // first
case 11 => 11 -> 22 // second

// A blank line separates alignment blocks.
case `ignoreMe` => 111 -> 222
}

// Align assignments of similar type.
def name = column[String]("name")
def status = column[Int]("status")
val x = 1
val xx = 22

// Align sbt module IDs.
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"com.lihaoyi" %% "sourcecode" % "0.1.1"
)

关于scala - 代码格式:如何在理解中对齐<-?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47465834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com