Scala | tags

Scala Python 文件读取跳过转义字符 20-06-04

在文件读取的时候,会遇到非法转义字符,导致文件按行读取失败。此时可以通过忽略转义字符来解决。本文记录了 scala 和 python 的方法。 […] 有 50G 的服务器日志,拆分为几千个 txt 文件,编码是 utf8,使用 scala 和 python 按行处理: […] def main(args: Array[String]): Unit = { for …

Scala uniform access principle 20-01-31

虽然代码写的很水,但是我对各种编程语言一直比较感兴趣。除了工作中使用的 Java 之外,自己也了解 Python,Groovy,Scala,Kotlin,Clojure,Go,Rust.其中 Python 和 Scala 在工作中也偶尔使用。了解不同的编程语言语法对于编程思维的影响还是蛮有意思的。 例如,只会 Java 的开发者可能没有听过模式匹配 (pattern match). …

Highlights in Scala for Impatient 2nd 20-01-15

key points in scala-for-impatient 2nd book, best book for java developer to use scala in a rush. scala-for-impatient 章节摘要,这本书对于 Java 开发者快速上手 Scala 帮助很大。

Scala Collection Tips 19-05-19

scala collection 提供了一整套独立于 Java 的高性能集合,使用上非常灵活,所以需要清楚一些常用的方法: […] //reduce 是一个二元函数,遍历整个集合 List(1, 3, 5).reduceLeft(_ + _) // == ((1+3)+5) //reduceRight start from end of the collection //also …

Useful Scala Code Snippets 19-04-26

多个 map 合并,key 相同时则 value 相加

Scala Future 19-04-21

some notes on scala future, includes: […] import java.time._ import scala.concurrent._ import ExecutionContext.Implicits.global Future { Thread.sleep(10000) println(s"This is the future at …

Pattern Matching Anonymous Function 19-03-31

Scala 中很多使用 if 的地方都可以用 match case 来替换。常见的就是下面的这种写法: […] val res = msg match { case it if it.contains("H") => "Hello" case _ => "Other" } //更常见的用法是去匹配参数的模式: case …

Scala Type Class 19-03-31

scala type class notes: 关于 scala type class 非常好的文章 […] //scala 没有专门的 type class 语法,而是借助 trait + implicit + context bound 来实现的, //所以很多时候识别 type class 比较困难。 //type class 由三部分构成 //1. type class: 即 …

Scala 2 Implicit 19-03-30

//隐式参数是在调用时可以自动填充的参数,需要在调用范围内(scope) 有一个隐式变量可供填充。 def addInt(i:Int)(implicit n: Int) = i + n //需要提供一个隐式变量 n implicit val sn = 1 addInt(2) // 3 //如果有两个满足类型的隐式变量,则在编译 addInt(2) 时报错 //scala …