For example, in React application, we have initial state;

const data = {
nextId: 4,
todoFilter: 'SHOW_ALL',
todos: [
{ id: 1, title: 'Hug Unicorn', completed: false },
{ id: 2, title: 'Mess with Texas', completed: false },
{ id: 3, title: 'Do Laundry', completed: true }
],
ui: {
filterGroups: {
status: false
}
}
}

We have a toggle button, which everytime, it is toggle 'ui.filterGroups.status' to true/false.

Whenever we have to update nested object, we should always comes up a word 'Lens'!

Here is how to do it:

import { State, compose  } from 'crocks'
import {lensPath, lensProp, over, not} from 'ramda'
const { modify } = State // ui -> filterGroups -> status const lnsFilterGroups = lensPath(['ui', 'filterGroups'])
export const toggleFilterGroup = ({ group }) => {
const lns = compose(
lnsFilterGroups,
lensProp(group)
) return modify(over(lns, not))
}

[Functional Programming] Using Lens to update nested object的更多相关文章

  1. Functional Programming without Lambda - Part 2 Lifting, Functor, Monad

    Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...

  2. BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2

    In this blog post I will talk about the changes coming in Angular 2 that will improve its support fo ...

  3. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  4. Functional Programming without Lambda - Part 1 Functional Composition

    Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...

  5. a primary example for Functional programming in javascript

    background In pursuit of a real-world application, let’s say we need an e-commerce web applicationfo ...

  6. Functional programming

    In computer science, functional programming is a programming paradigm, a style of building the struc ...

  7. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

  8. Functional programming idiom

    A functional programming function is like a mathematical function, which produces an output that typ ...

  9. 关于函数式编程(Functional Programming)

    初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...

随机推荐

  1. 获取修改CSS

    获取CSS使用方法css("CSS属性名称"), 示例css("color") 设置CSS使用方法css("CSS属性名称","属 ...

  2. 安装ipython和jupyter

    本节内容: 安装ipython 安装jupyter Pycharm介绍 Python软件包管理 一.安装ipython 1. python的交互式环境   2. 安装ipython 可以使用pip命令 ...

  3. 自己实现一个和PYTHON的库一模一样的sha_256算法

    同时在看一本书<从零开始-自己动手写区块链>, 这书讲得易懂,我也动手实践一下. 这个算法和python3本身的实现相同, 所以,同样的字串,摘要是相同的. import struct i ...

  4. (APIO2014)序列分割

    题解: 我也不知道为啥上午上课讲了我昨天看的3题 这题关键在于发现操作顺序无关的 可以发现最终答案是任意两段乘积的和 那这个东西显然是可以dp的 然后可以斜率优化一波 nklongn 另外上课讲的是当 ...

  5. sdoi<序列计数>

    链接:https://www.luogu.org/problemnew/show/P3702 题解: 碰到计数题都要想想容斥 就跟碰到最大值最小要想想二分一样 考虑没有一个数是质数 那就确定了每一个数 ...

  6. BZOJ1567 [JSOI2008]Blue Mary的战役地图 二分答案 哈希

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1567 题意概括 给出两个n*n的数字矩阵,问最大公共正方形边长. 题解 先二分答案一个m,对于每一 ...

  7. 【Java】 剑指offer(53-1) 数字在排序数组中出现的次数

    正文 本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 统计一个数字在排序数组中出现的次数.例如输入排序数组{1, ...

  8. 090实战 Hadoop离线项目介绍(不包括程序)

    一:项目场景 1.需求分析 根据用户行为数据进行程序的处理,得到结果保存到关系型数据库中 需要收集用户(系统使用者)在不同客户端上产生的用户行为数据,最终保存到hdfs上 需要明确收集字段的相关信息, ...

  9. bootstrap table使用总结

    使用bootstrap table可以很方便的开发后台表格,对数据进行异步更新,编辑.下面就来介绍一下bootstrap table的详细使用方法: 因为之前在官网也找了很久的教程,源码感觉隐藏的比较 ...

  10. ie浏览器的版本

    原文链接:https://www.cnblogs.com/XCWebLTE/archive/2017/06/15/7017338.html function IEVersion() { var use ...