Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Functional Kotlin

You're reading from   Functional Kotlin Extend your OOP skills and implement Functional techniques in Kotlin and Arrow

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788476485
Length 350 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (22) Chapters Close

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
1. Kotlin – Data Types, Objects, and Classes FREE CHAPTER 2. Getting Started with Functional Programming 3. Immutability - It's Important 4. Functions, Function Types, and Side Effects 5. More on Functions 6. Delegates in Kotlin 7. Asynchronous Programming with Coroutines 8. Collections and Data Operations in Kotlin 9. Functional Programming and Reactive Programming 10. Functors, Applicatives, and Monads 11. Working with Streams in Kotlin 12. Getting Started with Arrow 13. Arrow Types 14. Kotlin's Quick Start 1. Other Books You May Enjoy Index

Introduction to Streams


As we mentioned earlier, Streams were first introduced from Java 8. Starting from Java 8, Java started to give more focus to functional programming and started to add functional features gradually.

Kotlin, on the other hand, started to add functional features from day one. Kotlin added functional features and interfaces. While working with Java, you can use Streams only if you use Java 8 and later versions, but with Kotlin you can still use Streams, even when working with JDK 6.

So, what are Streams? You can think of Streams as an abstract layer over a sequence of elements to perform aggregate operations. Confused? Let's take a code example and then try to understand:

  fun main(args: Array<String>) { 
      val stream = 1.rangeTo(10).asSequence().asStream() 
      val resultantList = stream.skip(5).collect(Collectors.toList()) 
      println(resultantList) 
  } 

The output is as follows:

In the preceding program, what we did was create an IntRange value, create...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images