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的更多相关文章

  1. 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 ...

  2. learning scala akka actorySystem create and close

    package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala. ...

  3. hive udaf 用maven打包运行create temporary function 时报错

    用maven打包写好的jar,在放到hive中作暂时函数时报错. 错误信息例如以下: hive> create temporary function maxvalue as "com. ...

  4. SqlServer中 CREATE PARTITION FUNCTION使用

    表分区的操作三步走: 1.创建分区函数 CREATE PARTITION FUNCTION xx1(int) 解释:在当前数据库中创建一个函数,该函数可根据指定列的值将表或索引的各行映射到分区. 语法 ...

  5. learning scala akka ask_pattern

    package com.example import akka.actor._ import akka.util.Timeout object Tutorial_03_Ask_Pattern exte ...

  6. Inverse/Implicit Function Theorem

    目录 4.1 The Inverse Function Theorem The Implicit Function Theorem 4.3 Curves and Surfaces 4.4 The Mo ...

  7. learning scala implicit class

    隐式类可以用来扩展对象的功能非常方便 example: object ImplicitClass_Tutorial extends App { println("Step 1: How to ...

  8. learning scala Function Recursive Tail Call

    可以使用scala库,可以从字面上看出是在调用 递归函数: code import scala.util.control.TailCalls._ val arrayDonuts: Array[Stri ...

  9. 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( ...

随机推荐

  1. Authentication源码解析

    1.获取当前的 Subject. 调用 SecurityUtils.getSubject(); 从当前线程的threadLocals属性中获取Subject对象 SecurityUtils publi ...

  2. 立体像对空间前方交会-共线方程求解法(python实现)

    一.原理 二.步骤 a.用各自像片的角元素计算出左右像片的旋转矩阵R1和R2. b.有同名像点列出共线方程. c.将方程写为未知数的线性方程形式,计算线性系数. d.写出误差方程,系数矩阵与常数项. ...

  3. django类视图as_view()方法解析

    使用视图函数时,django完成URL解析之后,会直接把request对象以及URL解析器捕获的参数(比如re_path中正则表达捕获的位置参数或关键字参数)丢给视图函数,但是在类视图中,这些参数不能 ...

  4. C#方法(用法,参数)

    方法:是一种用于实现可以由对象或类执行的计算或操作的成员,是一个已命名的语句集.方法就是把一些相关的语句组织到一起,用来执行一个任务的语句块.比如每个C#程序至少带一个main函数 1.格式:修饰符  ...

  5. 在论坛中出现的比较难的sql问题:19(row_number函数 行转列、sql语句记流水)

    原文:在论坛中出现的比较难的sql问题:19(row_number函数 行转列.sql语句记流水) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记 ...

  6. 基于MFC的网页ActiveX控件开发全程实录2(js向ActiveX控件传递参数)

    原文转自 https://blog.csdn.net/qianbin3200896/article/details/81452822 1.ActiveX控件部分(JS到ActiveX控件)继续上一篇博 ...

  7. 多线程使用libcurl

    curl默认情况下有两个地方是线程不安全的, 需要特殊处理, 1是curl_global_init 这个函数必须单线程调用, 2是默认多线程调用https会莫名其妙的挂掉, 以下是网上的解决方案 ht ...

  8. ABP 基于DDD的.NET开发框架 学习(一)

    ABP总体介绍 ABP是ASP.NET Boilerplate Project,ASP.NET样板项目. ABP框架定位于快速开发 ABP是一个用于最快实践和流行开发现代Web应用程序的新起点,旨在成 ...

  9. vue函数化组件 functional

    需要在组件中把functional 设置为true 一个函数化组件像这样: Vue.component('testcomponent', { functional: true, // 为了弥补缺少的实 ...

  10. Android笔记(四) Activity之间的数据传递

    我们之前使用Intent进行Activity之间的跳转,其实Intent还可以在启动活动的时候传递数据. Intent提供了一系列的putExtra方法以便我们把想要传递的数据暂存在Intent中,待 ...