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. A Reusable Aspect for Memory Profiling

    例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...

  2. CSS实现列表li边框重合问题

    CSS实现列表li边框重合问题 2017年04月13日 21:04:18 阅读数:5066 在我们写东西的时候经常要用到ul,但是也经常会出现li边框重合的问题,如下图:  可以看到每个格子的右边框和 ...

  3. WPF TextBox 仅允许输入数字

    因为在 IValueConverter 实现中,当文本不能转换为目标类型时返回 DependencyProperty.UnsetValue ,Validation.GetHasError 返回 tru ...

  4. 闲谈Spring-IOC容器

    闲聊 无论是做j2ee开发还是做j2se开发,spring都是一把大刀.当下流行的ssh三大框架中,spring是最不可替代的,如果不用hibernate和struts,我觉得都无关紧要,但是不能没有 ...

  5. angularJS之ng-bind与ng-bind-template的区别

    ng-bind-template 指令用于告诉 AngularJS 将给定表达式的值替换 HTML 元素的内容. 当你想在 HTML 元素上绑定多个表达式时可以使用 ng-bind-template ...

  6. (转)Bootstrap 之 Metronic 模板的学习之路 - (5)主题&布局配置

    https://segmentfault.com/a/1190000006736457 Theme Setup 主题配置 Metronic comes with 6 color themes,defa ...

  7. sql 导入excel 遇到问题

    ALTER TABLE tab1 add id int identity primary key (注意:必须加identity,否则添加会失败) //导入excel时候 先把主键去掉 变为可为空,之 ...

  8. React-Router ---withRouter

    import React from 'react' import { withRouter } from 'react-router' const Hello = (props) => { re ...

  9. phpStudy 升级 MySQL版本

    1:停止phpStudy ,Mysql 服务;删除Mysql 文件夹 替换为新版本的Mysql 2:复制一份 my-default.ini,改名 my.ini ,打开,在最后面加上: basedir= ...

  10. 单调队列 && 单调栈

    单调队列 && 单调栈 单调队列 维护某个滑动区间的min or max,可用于dp的优化 以维护min为例,采用STL双端队列实现 每次加入元素x前 先检查队首元素==滑动后要删除的 ...