learning scala How To Create Implicit Function
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 convert a String to the wrapper String class")
object DonutConverstions {
implicit def stringToDonutString(s: String) = new DonutString(s)
}
println("\nStep 3: How to import the String conversion so that it is in scope")
import DonutConverstions._
println("\nStep 4: How to create String values")
val glazedDonut = "Glazed Donut"
val vanillaDonut = "Vanilla Donut"
println("\nStep 5: How to access the custom String function called isFavaoriteDonut")
println(s"Is Glazed Donut my favorite Donut = ${glazedDonut.isFavoriteDonut}")
println(s"Is Vanilla Donut my favorite Donut = ${vanillaDonut.isFavoriteDonut}")
result
Step 1: How to create a wrapper String class which will extend the String type Step 2: How to create an implicit function to convert a String to the wrapper String class Step 3: How to import the String conversion so that it is in scope Step 4: How to create String values Step 5: How to access the custom String function called isFavaoriteDonut
Is Glazed Donut my favorite Donut = true
Is Vanilla Donut my favorite Donut = false
learning scala How To Create Implicit Function的更多相关文章
- learning scala How To Create Variable Argument Function - varargs :_ *
Scala collection such as List or Sequence or even an Array to variable argument function using the s ...
- learning scala akka actorySystem create and close
package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala. ...
- hive udaf 用maven打包运行create temporary function 时报错
用maven打包写好的jar,在放到hive中作暂时函数时报错. 错误信息例如以下: hive> create temporary function maxvalue as "com. ...
- SqlServer中 CREATE PARTITION FUNCTION使用
表分区的操作三步走: 1.创建分区函数 CREATE PARTITION FUNCTION xx1(int) 解释:在当前数据库中创建一个函数,该函数可根据指定列的值将表或索引的各行映射到分区. 语法 ...
- learning scala akka ask_pattern
package com.example import akka.actor._ import akka.util.Timeout object Tutorial_03_Ask_Pattern exte ...
- Inverse/Implicit Function Theorem
目录 4.1 The Inverse Function Theorem The Implicit Function Theorem 4.3 Curves and Surfaces 4.4 The Mo ...
- learning scala implicit class
隐式类可以用来扩展对象的功能非常方便 example: object ImplicitClass_Tutorial extends App { println("Step 1: How to ...
- learning scala Function Recursive Tail Call
可以使用scala库,可以从字面上看出是在调用 递归函数: code import scala.util.control.TailCalls._ val arrayDonuts: Array[Stri ...
- learning scala Function Composition andThen
Ordering using andThen: f(x) andThen g(x) = g(f(x)) Ordering using compose: f(x) compose g(x) = f(g( ...
随机推荐
- 小程序--e.target和e.currentTarget区别
事件捕获与事件冒泡 事件捕获是从外到内,事件冒泡是从内到外. 注意:不管是不是冒泡事件,都不会改变事件传递的参数值,都还是在dataset中获取(******) target:指事件源组件对象 ...
- LINUX驱动笔记 目录
笔记参考了宋宝华老师的<Linux设备驱动开发详解:基于最新的Linux 4.0内核>以及韦东山老师的嵌入式驱动教程 笔记开发环境: 单板:第一章到第八章使用TINY4412-1611:第 ...
- 将图片画到canvas 上的几种方法(转)
转自:https://blog.csdn.net/qq_15009739/article/details/82809525
- 全栈项目|小书架|服务器开发-NodeJS 项目分包
唠嗑 参考的是慕课网七月老师的课程,七月的课质量真的挺高的,推荐一波.这次的小书架项目源码不会全部公开,因为用了七月老师课程的绝大部分代码.虽然代码不全,但是只要思路看得懂,代码实现就很简单了. 小书 ...
- #448 div2 a Pizza Separation
A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- 路由基础(Routing)
查看本机路由表: [root@controller02 ~]# cat /etc/iproute2/rt_tables # # reserved values # 255 local 254 ...
- 编写Postgres扩展之一:基础
原文:http://big-elephants.com/2015-10/writing-postgres-extensions-part-i/ 编译:Tacey Wong Postgres提供了广泛的 ...
- js钩子函数实现一个简单动画
<!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...
- Apache老版本下载地址
有时候我们想做测试或者使用旧版本软件时,往往发现官方网站已经下架,以Apache为例: Apache旧版本下载地址:http://archive.apache.org/dist/httpd/ .... ...
- Computer Vision_33_SIFT:An Improved RANSAC based on the Scale Variation Homogeneity——2016
此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...