object Twice {
def apply(x: Int): Int = x *
def unapply(z: Int): Option[Int] = if (z % == ) Some(z / ) else None
} object TwiceTest extends Application {
val x = Twice()
x match { case Twice(n) => Console.println(n) } // prints 21
}
object TwiceTest extends Application {
val x = Twice.apply()
Twice.unapply(x) match { case Some(n) => Console.println(n) } // prints 21
}

learning scala extracors example的更多相关文章

  1. learning scala 数组和容器

    数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] ...

  2. learning scala control statement

    1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: In ...

  3. learning scala read from file

    scala读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile ...

  4. learning scala write to file

    scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile ...

  5. learning scala output to console

    控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println(" ...

  6. learning scala read from console

    控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example ...

  7. learning scala 变量

    scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not ...

  8. learning scala 操作符

    scala 操作符: 算术运算符:  +  - *  / % 关系统运算符: > , < ,= ,!= ,>=,<=, 逻辑运算符: && . || , ! 位 ...

  9. learning scala akka ask_pattern

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

随机推荐

  1. RHEL6.5 移植使用CentOS 的YUM 步骤

    问题:使用 Red Hat Enterprise Linux Server(RHEL) yum安装软件时显示 This system is not registered with RHN. RHN s ...

  2. ELK学习笔记之配置logstash消费kafka多个topic并分别生成索引

    0x00 filebeat配置多个topic filebeat.prospectors: - input_type: log encoding: GB2312 # fields_under_root: ...

  3. flask 与 flask_migrate的使用

    flask 与 flask_migrate的使用 一.安装 pip install Flask-Migrate 二.简单使用 # 文件:manage.py from flask_migrate imp ...

  4. aria2 添加任务后一直在等待,不进行下载是什么情况?

    https://www.v2ex.com/t/567014 跑 aria2 的机器配置比较低,是 j1900+4G 的小机器,系统是 ubuntu18.04 ,所有的任务都是 bt 下载.aria2 ...

  5. MySQLNonTransientConnectionException: Could not create connection to database server.

    MySQLNonTransientConnectionException: Could not create connection to database server. Spring整合mybati ...

  6. Vue-webpack-hbuilderx 开发前端基本命令

    --创建Vue 项目 pc 需要装 node 环境 ,安装完之后,就可以在cmd中使用npm 命令了 1:npm install -g vue-cli  //电脑端需要安装vue 脚手架模板,电脑端一 ...

  7. 手写MVC框架(二)-代码实现和使用示例

    --------上一篇:手写MVC框架(一)-再出发----- 背景 书接上文,之前整理了实现MVC框架需要写哪些东西.这周粗看了一下,感觉也没多少工作量,所以就计划一天时间来完成.周末的时间,哪会那 ...

  8. React-Native中使用到的一些JS特性

    React Native - 调试技巧及调试菜单说明(模拟器调试.真机调试) https://www.hangge.com/blog/cache/detail_1480.html 1,解构赋值——de ...

  9. Java多线程 常见问题整理

    线程 什么是线程 线程是指程序在执行过程中,能够执行程序代码的一个执行单元. 线程和进程的区别 线程:一段程序执行过程中的一个执行单元,各个线程之间共享程序的内存空间以及一些进程级的资源,各线程拥有自 ...

  10. tac命令以及各种linux文件查看命令

    有许多命令都可以查看文件,不同的命令有不同的优点,可以针对不同的需要分别选择命令以提高效率:    cat     由第一行开始显示内容,并将所有内容输出    tac     从最后一行倒序显示内容 ...