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( ...
随机推荐
- 18 JSON、JSON字符串、反序列化
JSON教程 : https://www.runoob.com/python/python-json.html 概念 JSON是一种轻量级的数据交换格式,它是一种数据格式! JSON易于阅读.易于解析 ...
- go http简单的表单处理
//表单处理 package main import ( "net/http" "io" "fmt" &qu ...
- 网络地址转换(NAT)
NAT是解决ipv4地址短缺的方案之一 NAT是将位于子网中的主机与外网连通,子网中所有的主机都可以通过路由器的网络地址转换访问外网.对于外网来说该路由器相当于一台完整的主机,子网内所有主机对外网的访 ...
- STL中的函数对象实现负数的定义
// // main.cpp // STL中的函数对象 // // Created by mac on 2019/5/2. // Copyright © 2019年 mac. All rights r ...
- Powershell学习笔记:(一)、初识Powershell
什么是Powershell? MSDN上的说明是:PowerShell 是构建于 .NET 上基于任务的命令行 shell 和脚本语言. PowerShell 可帮助系统管理员和高级用户快速自动执行用 ...
- springboot笔记03——quickstart程序原理
一.前言 一个quickstart程序仅仅让我们初步了解一个框架,我们还需要透过现象看本质才能学好一个框架.所以这篇文章分析一下我上次写的springboot的入门程序. 二.原理分析 1.依赖分析 ...
- springboot 日志配置
maven依赖中添加了 spring-boot-starter-logging : <dependency> <groupId>org.springframework.boot ...
- javascript 箭头函数的使用 初学者必看
为了保证可读性,本文采用意译而非直译.另外,本文版权归原作者所有,翻译仅用于学习. 本文我们介绍箭头(arrow)函数的优点. 更简洁的语法我们先来按常规语法定义函数: 1 2 3 4 5 funct ...
- ELK文档--ELK简介
请参考:http://www.cnblogs.com/aresxin/p/8035137.html
- Flink原理(一)——基础架构
Flink系列博客,基于Flink1.6,打算分为三部分:原理.源码.实例以及API使用分析,后期等系列博客完成后再弄一个目录. 该系列博客是我自己学习过程中的一些理解,若有不正确.不准确的地方欢迎大 ...