learning scala stripMargin】的更多相关文章

(1)Scala中创建多行字符串使用Scala的Multiline String. 在Scala中,利用三个双引号包围多行字符串就可以实现. 代码实例如: val foo = """a bc d""" 运行结果为: a bc d (2) 上述方法存在一个缺陷问题,输入的内容,带有空格.\t之类,导致每一行的开始位置不能整洁对齐. 而在实际应用场景下,有时候我们就是确实需要在scala创建多少字符串,但是每一行需要固定对齐. 解决该问题的方法就是应…
package com.aura.scala.day01 import scala.util.matching.Regex object regularExpressionPatterns { def main(args: Array[String]): Unit = { // example 1 // .r 方法可便任意字符串变成一个正则表达式 val numberPatter: Regex = "[0-9]".r numberPatter.findFirstMatchIn(&quo…
数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] = Array(0, 0, 0) scala> val myStrArr = Array("BigData","hadoop","spark")myStrArr: Array[String] = Array(BigData, hadoop, s…
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读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile = Source.fromFile("text.txt")inputFile: scala.io.BufferedSource = non-empty iterator scala> for ( line <- inputFile.getLines()) println(lin…
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile = new PrintWriter("text.txt")outputFile: java.io.PrintWriter = java.io.PrintWriter@213c812a scala> outputFile.println("hello panzidong&q…
控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println("hello ");println("world")hello world…
控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example:scala> import io.StdIn._import io.StdIn._ scala> var i=readInt()2i: Int = 2 scala> var f=readFloat()2.2f: Float = 2.2 scala> var b=readBoolean…
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…
scala 操作符: 算术运算符:  +  - *  / % 关系统运算符: > , < ,= ,!= ,>=,<=, 逻辑运算符: && . || , ! 位运算符:&, |, ^,~,<<,>>,>>>(无符号右移) 赋值运算符: = 优先及由上及下…
package com.example import akka.actor._ import akka.util.Timeout object Tutorial_03_Ask_Pattern extends App { val system = ActorSystem("DonutStoreActorySystem") val donutInfoActor = system.actorOf(Props[DonutInfoActor], name="DonutInfoActor…
package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala.concurrent.ExecutionContext.Implicits.global object Tutorial_01_ActorSystem_Introduction extends App { println("Step1 : Create an actor system")…
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…
Partial函数的定义 scala> val isVeryTasty: PartialFunction[String, String] = { case "Glazed Donut" | "Strawberry Donut" => "Very Tasty"}isVeryTasty: PartialFunction[String,String] = <function1> scala> isVeryTasty(&qu…
可以使用scala库,可以从字面上看出是在调用 递归函数: code import scala.util.control.TailCalls._ val arrayDonuts: Array[String] = Array("Vanilla Donut", "Strawberry Donut", "Plain Donut", "Glazed Donut") println("\nStep : How to defin…
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…
package com.aura.scala.day01 object genericClasses { def main(args: Array[String]): Unit = { val stack = new Stack[Int] stack.push() stack.push() println(stack.pop()) println(stack.pop()) } } class Stack[A] { private var elements: List[A] = Nil def p…
code: package com.aura.scala.day01 object forComprehensions { def main(args: Array[String]): Unit = { val userBase = List(User(), User(), User(), User()) val twentySomethins = && userYonger.age < ) yield userYonger.name twentySomethins.foreach(…
package com.aura.scala.day01 import scala.util.Random object extractorObject { def main(args: Array[String]): Unit = { // val customer1ID = CustomerID("Sukyoung") // Sukyoung--23098234908 // customer1ID match { // case CustomerID(name) => pri…
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…
code: package com.aura.scala.day01 object patternMatching03 { //当不同类型对象需要调用不同方法时,仅匹配类型的模式非常有用. def goIDLE(device : Device) = device match { case p: Phone => p.screenOff case c:Computer => c.screenSaverOn } } abstract class Device case class Phone(mo…
code package com.aura.scala.day01 object patternMatching02 { def main(args: Array[String]): Unit = { def showNotifacation(notification: Notification):String = { notification match { case Email(sender, title, _) => s"You got an email from $sender w…
code: package com.aura.scala.day01 import scala.util.Random object patternMatching01 { def main(args: Array[String]): Unit = { val x:Int = Random.nextInt() // 一个模式匹配语句包括一个待匹配的值,match关键字,以及至少一个case 语句. x match { => "zero" => "one"…
package com.aura.scala.day01 object caseClasses { def main(args: Array[String]): Unit = { // 注意在实例化案例类时,并没有使用关键字new, 这是因为案例类有一个默认的apply // 方法来负责对象的创建. val frankenstein = Book("978-0486282114") println(frankenstein.isbn) val message1 = Message(&q…
reference : https://www.jetbrains.com/help/idea/install-and-set-up-product.html env in ubuntu 16.04 install command : $ sudo snap install intellij-idea-community --classic lunch command: intellij-idea-community…
package com.example import akka.actor._ object Tutorial_02_Tell_Pattern extends App { println("Step 1: Create an actory system") val system = ActorSystem("DonutStoreActorSystem") val donutInActor = system.actorOf(Props[DonutInActor], n…
object Twice { def apply(x: Int): Int = x * def unapply(z: Int): Option[Int] = == ) Some(z / ) else None } object TwiceTest extends Application { val x = Twice() x match { case Twice(n) => Console.println(n) } // prints 21 } object TwiceTest extends…
collect will apply a partial function to all elements of a Traversable and return a different collection…
If two Iterables aren't the same size, then zipAll can provide fillers for what it couldn't find a complement for. e.g. Iterable(x1, x2, x3) zipAll (Iterable(y1, y2), x, y) will return ((x1,y1), (x2, y2), (x3, y))):  …