case class Book(title: String, authors: List[String], year: Int)
val books: List[Book] = List(
Book("Structure and Interpretation of Computer Programs",
List("Abelson, Harold", "Sussman, Ge
我有一個書單: case class Book(name:String,authors:List[String])
val books:List[Book] = List(
Book(name="Code in Scala",authors=List("Viny","Vinay")),
Book(name="Dance in 30 days",authors=Li
的Haskell Wikibook提供一個 foldl1 :: (a -> a -> a) -> [a] -> a
foldl1 f (x:xs) = foldl f x xs
foldl1 _ [] = error "Prelude.foldl1: empty list"
是不工作。我試圖編譯這個版本是: myFoldl1 :: (a -> a -> a) -> [a] ->
什麼是高階函數的等效表達式如下? def isRepeated:Boolean = {
prev match {
case Some(a) => a.prev match {
case Some(b) => b.equals(this)
case None => false
}
case None => false
}
}