Scala : headOption

println(List(1,2,3)
.map(_*2)
.filter(_%3 ==0)
.headOption
.getOrElse(100)
)
6
println(List(1,2)
.map(_*2)
.filter(_%3 ==0)
.headOption
.getOrElse(100)
)
100

--

--

--

On a continuing learning journey..

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Use Spring Data Jpa to Query JSONB Column || Spring Boot

Developing Unit Tests with Mocha

Using request to Fetch JSON over HTTP

A Quick Intro to Dependency Injection: What It Is, and When to Use It

Call the Logic from the Interface

images/new_phoenix/welcome_with_form.png

Chapter 14 Single-Page Apps with React

Making a generative recreation of The Portrait of an Acrobat by Paul Klee in p5.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Learn

Learn

On a continuing learning journey..

More from Medium

Polymorphic functions in Scala

Scala: Partial functions

[Scala] Implicit Parameters

Essential effects