Scala函数式编程课后习题答案(第四章)(更新ing)
2017-05-15 15:01
676 查看
Scala函数式编程课后习题答案(第四章)(更新ing)
练习4.1
trait Option[+A] { case object None extends Option[Nothing] case class Some[+A](value:A) extends Option[A] def map[B](f: A => B): Option[B]= this match { case None => None case Some(a) => Some(f(a)) } def flatMap[B](f:A=>Option[B]):Option[B] = this match { case None => None case Some(a) => f(a) } def getOrElse[B>:A](default: => B):B = this match { case None => default case Some(a) => a } def orElse[B>:A](ob: => Option[B]):Option[B] = this match { case None => ob case _ => this } def filter(f:A =>Boolean):Option[A] = this match { case Some(a) if (f(a)) => this case _ => None } }
相关文章推荐
- Scala函数式编程课后习题答案(第三章)(更新ing)
- IBM-PC汇编语言程序设计(第二版)课后习题答案(清华大学出版社)(沈美明,温冬蝉著)第四章
- Java语言程序设计基础篇第四章课后习题(保持更新)
- Scala函数式编程课后习题答案(第五章)
- 计算机操作系统第四版第四章课后习题答案
- 鸟哥的Linux私房菜基础学习篇(第二版)第四章课后习题与答案
- 《C语言的科学与艺术》课后习题答案第四章(部分)
- 计算机操作系统第四版第四章课后习题答案
- 自考本科《计算机网络原理》课后习题参考答案(第四章)
- 《学习OpenCV》课后习题解答(第四章)(仅供参考)(不断更新)
- 鸟哥的linux私房菜基础学习篇课后习题与答案 第四章
- 《学习OpenCV》课后习题解答(第四章)(仅供参考)(不断更新)
- C++Primer 中文版 第五版 第四章课后习题答案
- C++Primer Plus笔记——第四章 复合类型及课后习题答案
- 《C语言程序设计教程》(主编黄迪明、余勤)第四章课后习题答案
- 3500份课程课后习题答案与大家分享~~
- 汇编语言王爽(第二版)课后习题答案
- 数据结构实践(有的数据结构课后习题答案),红色是答案
- 《机器学习》(周志华)课后习题参考答案
- 模板元编程第六章课后习题(非答案)20151206