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( ...
随机推荐
- Python 数据结构理解分享
摘要:分享学习Python数据结构的一些理解,主要包含序列(如列表和元组),映射(如字典)以及集合3中基本的数据结构,以及可变和不可变数据类型. Python 中的数据结构是根据某种方式将数据元素组合 ...
- Hadoop 求单词count数
package com.yw.hadoop273; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongW ...
- Map、FlatMap 和 Reduce
Map 作用是生成一个新数组,遍历原数组,将每个元素拿出来做一些变换然后 append 到新的数组中. [1, 2, 3].map((v) => v + 1) // -> [2, 3, 4 ...
- 题解-APIO2019路灯
problem \(\mathtt {loj-3146}\) 题意概要:一条直线上有 \(n+1\) 个点和 \(n\) 条道路,每条道路连通相邻两个点.在 \(q\) 个时刻内,每个时刻有如下两种操 ...
- win7实现tensorflow中的物体识别
实现条件: 1.win7 2.python 3.运行所需要的库:matplotlib.lxml.pillow.Cython 具体参考:https://github.com/tensorflow/mod ...
- MonkeyRunner——Mac
1. MonkeyRunner介绍: Android的SDK中集成了三个可用来进行自动化测试的工具:Monkey.MonkeyRunner和Robotium.这三个测试工具都是基于黑盒测试. Monk ...
- apache ftp server 设置
<server xmlns="http://mina.apache.org/ftpserver/spring/v1" xmlns:xsi="http://www.w ...
- Spring Boot 揭秘与实战之RabbitMQ
Spring Boot 整合 RabbitMQ Spring Boot 整合 RabbitMQ 是非常容易,只需要两个步骤. 首先,在 pom.xml 中增加 RabbitMQ 依赖. <dep ...
- rabbitMQ centos7 的安装
安装erlang 1:下载erlang. http://erlang.org/download/otp_src_20.3.tar.gz 2:把erlang压缩包上传到Linux服务器上,并解压.我的解 ...
- 四:MySQL系列之Python交互(四)
该篇主要介绍MySQL数据库的分表.以及与Python的交互的基本操作等. 一.拆分表操作 1.1 准备工作 创建数据库 --> 使用数据库 --> 创建数据表 --- 添加记录 -- ...