首页 > Web开发 > 详细

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

时间:2016-03-01 06:21:00      阅读:118      评论:0      收藏:0      [点我收藏+]

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()

原文:http://www.cnblogs.com/Answer1215/p/5229556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!