[Immutable,js] Iterating Over an Immutable.js Map()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Immutable,js] Iterating Over an Immutable.js Map()相关的知识,希望对你有一定的参考价值。

Immutable.js provides several methods to iterate over an Immutable.Map(). These also apply to the other immutable structures found within the Immutable.js family, such as Set and List. The primary methods are map and forEach, but we will also cover filter and groupBy.

 

// map()
  return todos.map(todo => {
    return todo.text
  });

// filter()
  return todos.filter(todo => {
    return todo.completed;
  })


// groupBy() --> return new Immtuable Map
  return todos.groupBy(todo => {
    return todo.completed
  })

 

Notice, only forEach method will actually change its value!

// forEach()
function markAllTodosAsComplete(todos) {
  return todos.forEach(todo => {
    todo.completed = true
  });
}

 

以上是关于[Immutable,js] Iterating Over an Immutable.js Map()的主要内容,如果未能解决你的问题,请参考以下文章

[Immutable.js] Exploring Sequences and Range() in Immutable.js

[Immutable.js] Working with Subsets of an Immutable.js Map()

[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes

[Immutable.js] Differences between the Immutable.js Map() and List()

[Immutable.js] Transforming Immutable Data with Reduce

Immutable.js使用教程记录