Ordering using andThen: f(x) andThen g(x) = g(f(x)) Ordering using compose: f(x) compose g(x) = f(g(x)) println("Step 1: Assume a pre-calculated total cost amount") val totalCost: Double = println("\nStep 2: How to define a val function to…
[machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function?wiki上有一句解释我觉得很到位,引用一下:The loss function quantifies the amount by which the prediction deviates from the actual values.Loss Function中文损失函数,适用于用于统计,经济,机…
Scala collection such as List or Sequence or even an Array to variable argument function using the syntax :_ *. code : def printReport(names: String*) { println(s"""Donut Report = ${names.mkString(" - ")}""") } prin…
println("Step 1: How to create a wrapper String class which will extend the String type") class DonutString(s: String) { def isFavoriteDonut: Boolean = s == "Glazed Donut" } println("\nStep 2: How to create an implicit function to…
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: Int = 1 2. while statement 3. do.. while statement 4 for statement for ( 变量 <- 表达式 ) { 语句块}: scala> for ( i <- 1 to 3 ) println(i)123 scala> for…
scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not found: value test test = "only1" ^<console>:12: error: not found: value test val $ires0 = test ^ var :可被多次赋值. scala> var test2 = &qu…
1. Arbitrary multi parameters funcs sum(1,2,3,4,5) = sum(1 to 5: _*)the equal '=' can be ignored if there is none return val def sum(args: Int*) = { var result = 0 for(arg <- args) result += arg result } scala Array Buffer to Java List: import sca…
The Scala collections library provides specialised implementations for Sets of fewer than 5 values (see the source). The iterators for these implementations return elements in the order in which they were added, rather than the consistent, hash-based…
(1)Scala中创建多行字符串使用Scala的Multiline String. 在Scala中,利用三个双引号包围多行字符串就可以实现. 代码实例如: val foo = """a bc d""" 运行结果为: a bc d (2) 上述方法存在一个缺陷问题,输入的内容,带有空格.\t之类,导致每一行的开始位置不能整洁对齐. 而在实际应用场景下,有时候我们就是确实需要在scala创建多少字符串,但是每一行需要固定对齐. 解决该问题的方法就是应…
package com.aura.scala.day01 object sealedClassed { def findPlaceToSit(piece: Furniture) = piece match { case a: Couch => "Lie on the couch" case b: Chair => "Sit on the chair" } } //sealed定义密封类 sealed abstract class Furniture ca…