zhimoe

the craft of programming


  • 首页

  • 归档

  • 编程

  • 翻译

  • 项目

  • 关于

  • 搜索

Useful Scala Code Snippets

时间: 2019-04-26   |   分类: 编程   | 字数: 369 字 | 阅读: 1分钟

merge two map and sum its values

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

val map1 = Map(1 -> 1, 2 -> 2)
val map2 = Map(1 -> 11, 3 -> 3)
val map3 = Map(1 -> 111, 3 -> 3)

val mapList = List(map1, map2, map3)

val merged = mapList.reduce((m1, m2) =>

  m1 ++ m2.map { case (k, v) => k -> (v + m1.getOrElse(k, 0)) }
)
阅读全文 »

Scala Future

时间: 2019-04-21   |   分类: 编程   | 字数: 315 字 | 阅读: 1分钟

some notes on scala future, includes:

  • future
  • executor context
  • await future result
  • callback
  • recover
阅读全文 »

Spring Boot Notes

时间: 2019-04-14   |   分类: 编程   | 字数: 2102 字 | 阅读: 5分钟

一些容易忘记的spring boot知识要点.

注意,.yaml和.yml文件没任何区别.

配置

SpringBootApplication注解

@SpringBootApplication
// <=等价=>
@Configuration
@ComponentScan
@EnableAutoConfiguration

阅读全文 »

Pattern Matching Anonymous Function

时间: 2019-03-31   |   分类: 编程   | 字数: 577 字 | 阅读: 2分钟

Scala中很多使用if的地方都可以用match case来替换.常见的就是下面的这种写法:

val res = msg match {
	case it if it.contains("H") => "Hello"
	case _ => "Other"
}
//更常见的用法是去匹配参数的模式:
case class Player(name: String, score: Int)
def message(player: Player) = player match {
  case Player(_, score) if score > 100000 =>
    "Get a job, dude!"
  case Player(name, _) =>
    "Hey, $name, nice to see you again!"
}
def printMessage(player: Player) = println(message(player))
阅读全文 »

Scala Type Class

时间: 2019-03-31   |   分类: 编程   | 字数: 982 字 | 阅读: 2分钟

scala type class notes: 关于scala type class非常好的文章

阅读全文 »
3 4 5 6 7 8 9 10 11
zhimoe

zhimoe

Captain your own Ship.

61 日志
4 分类
38 标签
RSS 订阅
GitHub ZhiHu
书签
  • 可视化学习Git
  • 美团技术团队
  • 艺术绘画
  • 500px
  • RustCheatsheet
  • 谷歌机器学习课程
标签云
  • Code
  • Java
  • Scala
  • Python
  • Rust
  • Spring
  • Docker
  • Aop
  • Aurulent
  • Cheatsheet
© 2010 - 2022 zhimoe
0%