Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
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
Authors (2):
Arrow left icon
Mario Arias Mario Arias
Author Profile Icon Mario Arias
Mario Arias
Rivu Chakraborty Rivu Chakraborty
Author Profile Icon Rivu Chakraborty
Rivu Chakraborty
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

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 15. Other Books You May Enjoy

Set and MutableSet


Just like List, Set also has the following two variants in Kotlin:

  • Set
  • MutableSet

Set is read-only and MutableSet is the mutable version of Set, which contains the read-write functionalities.

Note

Just like with list, set values also have read-only functions and properties like size, iterator(), and so on. We are skipping mentioning them here to avoid redundant contents in this book. Also, please note that set doesn't do ordering like list (unless you use OrderedSet). So, it lacks the functions which involve orders like indexOf(item), add(index, item), and so on.

Sets in collections represent mathematical sets (as in set theory).

The following is an example with MutableSet:

fun main(args: Array<String>) { 
    val set = mutableSetOf(1,2,3,3,2) 
 
    println("set $set") 
 
    set.add(4) 
    set.add(5) 
    set.add(5) 
    set.add(6) 
 
    println("set $set") 
} 

The following is the output:

The output clearly shows that, even though we added multiple duplicate items to...

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 $19.99/month. Cancel anytime
Banner background image