是否真的需要围绕最终元组的括号?没有它们就不能编译,编译器只尝试添加Sort("time")并抱怨它需要一个元组.
val maxSortCounts: Map[Sort, Int] =
sorts.map(s => s -> usedPredicates.map(pred => pred.signature.count(_ == s)).max)
.toMap + ((Sort("time"), 1))
Run Code Online (Sandbox Code Playgroud)
我试图用一个较短的例子在REPL中重现这种行为,但它的行为与预期的一样.变量sorts是a Seq[Sort].
error: type mismatch;
found : <snip>.Sort
required: (<snip>.Sort, Int)
.toMap + (Sort("time"), 1)
Run Code Online (Sandbox Code Playgroud) 我得到这个字符串" &TOKEN=EC%2d1NK66318YB717835M"从一个WebService的结果,我需要用它来完成我的treatement但问题是,我需要转换%2d到它的ASCII值是-.所以我的String将是结束" &TOKEN=EC-1NK66318YB717835M"
我如何用scala执行此操作?
谢谢.
我正在尝试使用Slick的映射投影(版本1.0.0-RC1).但是下面的代码遵循网站上的示例(因为似乎没有任何适当的文档也没有可用的scaladocs)会产生类型错误:
object PDFDocs extends Table[(String,Option[String],String)]("DOCUMENTS"){
def id = column[String]("ID", O.PrimaryKey)
def title = column[Option[String]]("TITLE")
def tags = column[String]("TAGS")
def * = (id ~ title ~ tags).<>[PDFDocument](PDFDocument,PDFDocument unapply _)
}
case class PDFDocument(name: String,
title: Option[String],
tags: String)
Run Code Online (Sandbox Code Playgroud)
这是产生的错误:
error: type mismatch;
found: scala.slick.lifted.MappedProjection[docman.rdb.PDFDocument,(String,Option[String], String)]
required: scala.slick.lifted.ColumnBase[(String, Option[String], String)]
def * = (id ~ title ~ tags).<>[PDFDocument](PDFDocument,PDFDocument unapply _)
Run Code Online (Sandbox Code Playgroud) 我有以下表达式,希望通过了解如何简化Scala来学习Scala.
val r : Either[Exception, Long] = Right(100)
r fold (_ => (), uuid => account.setAccountUuid(uuid.toString))
Run Code Online (Sandbox Code Playgroud)
是否有可能使它比这更简洁?
谢谢!
我正在使用2D数组,我在下面的方法中尝试做的是交换两个值.'currentBoard'变量是一个不需要编辑的2D数组.'cpy'变量是'currentBoard'的副本,需要更改其变量.'nbt'和'bt'是用于指向2D数组中的索引的1D数组.如果有帮助,函数'copyBoard'的代码总是在下面
我遇到的问题是,当'cpy'数组中的值由于某种原因改变'currentBoard'中的值时,在标有**的行上.我真的无法弄清楚为什么会这样......
private void Swap(int[] nbt, int[] bt, ArrayList<State> children, String direction) {
int[][] cpy = copyBoard(currentBoard);
int temp = cpy[nbt[0]][nbt[1]];
**cpy[nbt[0]][nbt[1]] = currentBoard[bt[0]][bt[1]];
cpy[bt[0]][bt[1]] = temp;
children.add(new Board(cpy, this.getGOAL(), this.getRows(), this.getColumns(), (this.getDirections() + direction + ", ")));
}
Run Code Online (Sandbox Code Playgroud)
如果它有帮助,那么当代码在标有**的行上时,分配给变量的值
nbt = {1,0} bt = {0,0}
private int[][] copyBoard(int[][] state)
{
int[][] returnArray = new int[rows][columns];
for (int i = 0, j = 0; i*j < PUZZLE_SIZE; i++, j++)
{
returnArray[i] = state[i];
}
return returnArray;
}
Run Code Online (Sandbox Code Playgroud)