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
Mastering Immutable.js

You're reading from   Mastering Immutable.js Better JavaScript development using immutable data

Arrow left icon
Product type Paperback
Published in Sep 2017
Publisher Packt
ISBN-13 9781788395113
Length 216 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Adam Boduch Adam Boduch
Author Profile Icon Adam Boduch
Adam Boduch
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Why Immutable.js? FREE CHAPTER 2. Creating Immutable Data 3. Persistent Changes 4. Filtering Collections and Finding Items 5. Sequences and Side-Effects 6. Sorting Collections 7. Mapping and Reducing 8. Zipping and Flattening 9. Persistent Change Detection 10. Working with Sets 11. Comparing Collections 12. Combining Collections 13. Declarative Decision Making 14. Side-Effects in User Interfaces 15. Side-Effects in Node.js 16. Immutable Architecture

Sequence creation and iteration


There are two ways to create sequences: you can directly create sequence instances, passing them collection data, or you can transform existing collections, such as lists and maps, into sequences.

Basic sequence creation

You can create new sequences by passing the Seq() constructor JavaScript arrays or objects, as follows:

import { Seq } from 'immutable';

const myIndexedSeq = Seq([1, 2, 3]);
const myKeyedSeq = Seq({ one: 1, two: 2, three: 3 });

console.log('myIndexedSeq', myIndexedSeq.toJS());
// -> myIndexedSeq [ 1, 2, 3 ]
console.log('myKeyedSeq', myKeyedSeq.toJS());
// -> myKeyedSeq { one: 1, two: 2, three: 3 }

There are actually two types of sequence collections: Seq.Indexed and Seq.Keyed. The Seq() constructor, which is really just a function due to the absence of the new keyword, will return the correct type of collection depending on what's passed to it.

Note

Generally speaking, you don't have to worry about the distinction between indexed and keyed...

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