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. Windows Mysql安装

    一.从https://dev.mysql.com/downloads/windows/installer/5.6.html下载MySQL Installer 二.直接点击默认安装

  2. python+selenium二:定位方式

    # 八种单数定位方式:elementfrom selenium import webdriverimport time driver = webdriver.Firefox()time.sleep(2 ...

  3. 《转》 java.lang.OutOfMemoryError - 关于java的内存溢出

    java.lang.OutOfMemoryError: PermGen space PermGen space的全称是Permanent Generation space 是指内存的永久保存区域, 该 ...

  4. h5的图片预览

    h5的图片预览是个好东西,不需要保存到后台就能预览图片 代码也很短 <!DOCTYPE html> <html> <head> <meta charset=& ...

  5. python全栈开发day47-jqurey

    一.昨日内容回顾 二.今日内容总结 1.jquery的介绍 1).为什么要用jquery? # window.onload 事件有事件覆盖的问题,因此只能写一个事件. # 代码容错性差 # 浏览器兼容 ...

  6. Mysql 双主架构配置从复制

    引用自:https://blog.csdn.net/deeplearnings/article/details/78398526 https://www.cnblogs.com/ygqygq2/p/6 ...

  7. Ubuntu+Fedora进阶学习,指令迅速查询,Bug迅速查询(Ctrl+F)

    There is some notes while I am learning Ubuntu Operate System! (Ask Ubuntu & Fedora) 1-- Hard li ...

  8. 二分搜索-HihoCoder1128

    题目链接:https://hihocoder.com/problemset/problem/1128 题目描述: 题目大意就是要我们编程找出K在数组a中的大小排序后的位置. 代码实现: #includ ...

  9. 洛谷 P1141【BFS】+记忆化搜索+染色

    题目链接:https://www.luogu.org/problemnew/show/P1141 题目描述 有一个仅由数字 0 与 1 组成的n×n 格迷宫.若你位于一格0上,那么你可以移动到相邻 4 ...

  10. hdu 2844 Coins【多重背包】

    题目链接:https://vjudge.net/contest/228640#problem/F 转载于:http://www.voidcn.com/article/p-mxcorksq-gh.htm ...