Given that sequence, use reduceLeft to determine different properties about the collection. The following example shows how to get the sum of all the elements in the sequence:

scala> a.reduceLeft(_ + _)
res0: Int = 64

Don’t let the underscores throw you for a loop; they just stand for the two parameters that are passed into your function. You can write that code like this, if you prefer:

a.reduceLeft((x,y) => x + y)

The following examples show how to use reduceLeft to get the product of all elements in the sequence, the smallest value in the sequence, and the largest value:

scala> a.reduceLeft(_ * _)
res1: Int = 388800 scala> a.reduceLeft(_ min _)
res2: Int = 2 scala> a.reduceLeft(_ max _)
res3: Int = 20

scala _ parameter的更多相关文章

  1. Scala _ [underscore] magic

    I started learning Scala a few days before. Initially i was annoyed by the use of too many symbols i ...

  2. Scala _ 下划线

    1.引入包中的全部方法 import math._ //引入包中所有方法,与java中的*类似 2.表示集合元素 val a = (1 to 10).filter(_%2==0).map(_*2) / ...

  3. Scala underscore的用途

    _ 的用途 // import all import scala.io._ // import all, but hide Codec import scala.io.{Codec => _, ...

  4. Scala(一) —— 基础

    一.输出 println("Hello World") 二.变量与常量 1.变量用var表示,常量使用val表示 2.变量类型声明 var variableName : DateT ...

  5. Scala编程进阶

    跳出循环语句的3种方法... 2 多维数组... 3 Java数组与Scala数组缓冲的隐式转换... 3 Java Map与Scala Map的隐式转换... 3 Tuple拉链操作... 4 内部 ...

  6. Scala详解

    1       快速入门... 4 1.1             分号... 4 1.2             常变量声明... 4 1.2.1         val常量... 4 1.2.2  ...

  7. Scala编程 笔记

    date: 2019-08-07 11:15:00 updated: 2019-11-25 20:00:00 Scala编程 笔记 1. makeRDD 和 parallelize 生成 RDD de ...

  8. Scala基础语法 (一)

    如果你之前是一名 Java 程序员,并了解 Java 语言的基础知识,那么你能很快学会 Scala 的基础语法. Scala 与 Java 的最大区别是:Scala 语句末尾的分号 ; 是可选的. 我 ...

  9. Scala HandBook

    目录[-] 1.   Scala有多cool 1.1.     速度! 1.2.     易用的数据结构 1.3.     OOP+FP 1.4.     动态+静态 1.5.     DSL 1.6 ...

随机推荐

  1. selenium - css 定位

    前言: CSS(Cascading Style Sheets)是一种语言,它被用来描述 HTML 和 XML 文档的表现. CSS 使用选择器来为页面元素绑定属性.这些选择器可以被 selenium ...

  2. 完整的qt安装教程

    大家可能认为qt收费了 其实不是 大家直接点击 这个 Community 这里的下载 Download 然后呢 就跳转到这个界面 点击 Qt Offline Installer 就会跳到这个地方 滑下 ...

  3. AngularJS:Scope(作用域)

    ylbtech-AngularJS:Scope(作用域) 1.返回顶部 1. AngularJS Scope(作用域) Scope(作用域) 是应用在 HTML (视图) 和 JavaScript ( ...

  4. PHP下的命令行执行 php -S localhost -t public(public是根目录,也是入口文件所在目录,是LARAVEL的)

    PHP 的命令行模式     以下是 PHP 二进制文件(即 php.exe 程序)提供的命令行模式的选项参数,您随时可以通过 PHP -h 命令来查询这些参数. Usage: php [option ...

  5. 第11章 Tomcat的系统架构与设计模式

    11.1 Tomcat总体设计 11.1.1 Tomcat总体架构 Tomcat和核心有连个组件:Connector和Container,Connector是可以被替换的.一个container可以有 ...

  6. 记录一下学习Android的小知识

    目前要设计即时通讯的整体架构,包括服务端.Android.IOS.PC.平板等等系统,所以需要研究一下手机的实现方式,开始从Android入手,偶尔在这记录下小知识. ADT: 1.页面功能请求结构, ...

  7. 实验吧CTF题库-隐写术(部分)

    Spamcarver 用kali下载图片 root@sch01ar:~# wget http://ctf5.shiyanbar.com/stega/spamcarver/spamcarver.jpg ...

  8. activemq安装运行及其在springboot中的queue和topic使用

    安装activemq 运行 springboot使用 依赖 配置 Producer Consumer ComsumerTopic 使用 安装activemq http://activemq.apach ...

  9. java 调用系统外部的某个程序

    有时候我们java 调用系统外部的某个程序 可能需要调用系统外部的某个程序,此时就可以用Runtime.getRuntime().exec()来调用,他会生成一个新的进程去运行调用的程序. 此方法返回 ...

  10. leetcode876

    class Solution { public: ListNode* middleNode(ListNode* head) { if (head == NULL) { return nullptr; ...