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. wpf 来回拉动滚动条抛异常

    其中的控件,来回快速的来动滚动条,抛如下异常,但是完全代码捕捉不到. 这个树用到了VirtualizingStackPanel.IsVirtualizing="True".去掉该句 ...

  2. python3 + selenium 使用 JS操作页面滚动条

    js2 = "window.scrollTo(0,0);" #括号中为坐标 当不知道需要的滚动的坐标大小时: weizhi2 = driver.find_element_by_id ...

  3. JQuery中的工具类(五)

    一:1.serialize()序列表表格内容为字符串.返回值jQuery示例序列表表格内容为字符串,用于 Ajax 请求. HTML 代码:<p id="results"&g ...

  4. Web应用程序项目XXXX已配置为使用IIS。无法访问IIS 元数据库。您没有足够的特权访问计算机上的IIS

    错误图片:

  5. Mybatis中的like模糊查询四种方式

    1.  参数中直接加入%% param.setUsername("%CD%"); param.setPassword("%11%"); <select i ...

  6. LYK loves graph(graph)

    题目: LYK loves graph(graph) Time Limit:2000ms   Memory Limit:128MB LYK喜欢花花绿绿的图片,有一天它得到了一张彩色图片,这张图片可以看 ...

  7. Angular 中后台前端解决方案 - Ng Alain 介绍

    背景 之前项目使用过vue.js+iview,习惯了后端开发的我,总觉得使用不习惯,之前分析易企秀前端代码,接触到了angular js,完备的相关功能,类似后端开发的体验,让人耳目一新,全新的ang ...

  8. 存储过程,存储函数(Oracle)

    存储过程和存储函数 指存储在数据库中供所有用户程序调用的子程序叫存储过程.存储函数. 存储过程和存储函数的区别? 存储函数:可以通过return 语句返回函数值. 存储过程:不能 除此之外我们可以认为 ...

  9. Redis数据结构之sorted-set

    一:介绍 1.说明 与set的主要区别 sorted-set中的成员需要一个分数,分数可以重复的. 位置是有序的 二:Redis客户端 1.添加 如果key已经存在,再次添加一个key相同的,但是分部 ...

  10. PHP 扩展 MongoDB

    打开phpinfo 查看 nts(非线程) 还是 ts (线程),操作位数: 下载对应的版本的php_mongodb.dll 文件 下载链接: pecl mangodb下载 把文件解压出来 php_m ...