In this lesson, we’ll look at the propPath utility function. We’ll ask for a property multiple levels deep in an object and get back a Maybe. We’ll get a Just when the property exists at our path and a Nothing if any part of the path is undefined.

const propPath = require('crocks/Maybe/propPath')

const user = {
username: 'tester',
email: 'test@gmail.com',
address: {
street: '111 E. West St',
city: 'Anywhere',
state: 'PA',
postalCode: '19123-4567'
}
}; const getPostalCode = propPath(['address', 'postalCode']);
const zip = getPostalCode(user).option('not available'); console.log(zip) //'19123-4567'

[Javascript Crocks] Safely Access Nested Object Properties with `propPath`的更多相关文章

  1. [Javascript Crocks] Safely Access Object Properties with `prop`

    In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...

  2. Initializing nested object properties z

    public class Employee { public Employee() { this.Insurance = new Insurance(); } // Perhaps another c ...

  3. [Javascript Crocks] Flatten Nested Maybes with `chain`

    Sometimes, we run into situations where we end up with a Maybe within the context of another Maybe. ...

  4. javascript nested object merge

    javascript nested object merge deep copy Object reference type function namespace(oNamespace, sPacka ...

  5. [Functional Programming] Using Lens to update nested object

    For example, in React application, we have initial state; const data = { nextId: 4, todoFilter: 'SHO ...

  6. 67.基于nested object实现博客与评论嵌套关系

    1.做一个实验,引出来为什么需要nested object 冗余数据方式的来建模,其实用的就是object类型,我们这里又要引入一种新的object类型,nested object类型 博客,评论,做 ...

  7. Vue开发警告[Vue warn]: Avoid replacing instance root $data. Use nested data properties instead.

    Avoid replacing instance root $data. Use nested data properties instead. 翻译 避免替换实例根$data.请改用嵌套数据属性 错 ...

  8. JavaScript中你所不知道的Object(二)--Function篇

    上一篇(JavaScript中你所不知道的Object(一))说到,Object对象有大量的内部属性,而其中多数和外部属性的操作有关.最后留了个悬念,就是Boolean.Date.Number.Str ...

  9. 【Selenium】【BugList8】126邮箱定位不到“退出”按钮:Message: TypeError: can't access dead object

    [流程描述] 登录126邮箱,退出 [代码] #coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() #dr ...

随机推荐

  1. yaml标记语言的简介

    今天遇到yml这个文件,挺懵的.也是百度了一把. 这篇博文不错:http://www.ibm.com/developerworks/cn/xml/x-1103linrr/ 这图画得不错:http:// ...

  2. 《CSS Mastery》 读书笔记 (1)

    --本笔记中英混合,专业名词尽量不翻译,免得误解,如果不习惯,就不用往下看了,走好不送. 第一章 基础 人类的好奇心总是促使我们捣鼓,捣鼓是最好做有效的学习CSS的方法 In this chapter ...

  3. HTML简单入门

    - Java攻城狮学习路线 - 基本结构 标准文档:www.w3.org <!DOCTYPE html> <html> <head> <meta charse ...

  4. js基础---字符串方法

    // var str1="xudandan"; // 字符串长度 var str1_length=str1.length;console.log(str1);console.log ...

  5. 简繁体互换工具:opencc

    简繁体互换工具:opencc opencc是一个简体.繁体相互转换的命令行工具. 安装 下载软件包.在下载页面下载软件包(如1.0.4版本) 解压.通过命令解压:tar -xzvf opencc-1. ...

  6. 【SQL】ROWNUM和ROWID

    一.ROWNUM ROWNUM伪列是Oracle先查到结果集之后再加上去的一个伪列,这个伪列对符合条件的结果添加一个从1开始的序列号,并且序列号是从1开始增序排列的. SQL> select r ...

  7. 【Oracle】闪回表

    语法: FLASHBACK TABLE [ schema. ] table [, [ schema. ] table ]... TO { { { SCN | TIMESTAMP } expr| RES ...

  8. 乐乎共享wifi充电宝项目

  9. semiautomatic annotated tools

    在进行实验图像取样时,可能会用到大量的标签样本,拍摄大量图片进行手工标注要消耗大量时间,半自动化的标注工具可以节省一些时间. 原文链接:http://blog.sina.com.cn/s/blog_6 ...

  10. Matlab移植到Eigen用到的词条

    同型矩阵运算满足加法交换律.结合律:并存在单位元.逆元.和0元,为同型矩阵对加法的交换环. Eigen的简单运算参考:http://blog.163.com/jiaqiang_wang/blog/st ...