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. 自学Python十 爬虫实战三(美女福利续)

    我又来送福利啦!!!不同于上篇文章,这次我们的爬虫采用了多线程,一直以来被所谓的分布式  多线程  爬虫 给唬的怕怕的.今天就来一发多线程爬虫吧,还能看妹子图,想想就觉得很激动!!! 依然是流程解释: ...

  2. Oracle 循环调用存储过程

    create or replace procedure p_test_loop as --定义一个游标,并将查询结果集赋值给它 CURSOR c1 IS select * from tbltest w ...

  3. sql学习--insert

    insert的四种插入方式 第一种最简单的 into 和目标列的列表是可选的 intsert [into] tableA [(col1,col2)] values(val1,val2) 第二种 ins ...

  4. 仿QQ空间长图效果简易版--母亲节感恩

    手机网站 母亲节最火的两件事 1.NBA 杜兰特在获MVP催泪致辞献给母亲:她才是真的MVP. 2.QQ空间长图 ------------------------------------------- ...

  5. CSS多列布局(实例)

    前言 一列布局 二列布局 三列布局 1 一列布局 一列布局: HTML部分 <!DOCTYPE html> <html> <head> <meta chars ...

  6. CORS 和 JSONP

    跨域资源共享(CORS) 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制. CORS(Cross-Origin Resource Sharing) ...

  7. OI知识点

  8. Linux的那点事

    1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...

  9. 苹果双系统win8.1遇到的一些问题

    MacBook air是一款不错的电脑,详细没研究就不叙述好与坏了.只此记录自己使用这款笔记本遇到的问题. 一.安装双系统win8.1 1.下载镜像文件—>拷贝到ios内存中,一个8GU盘.ht ...

  10. 【PostgreSQL-9.6.3】函数(1)--数值型函数

    函数表示对输入参数返回一个特殊计算结果的值.PostgreSQL中的函数种类比较丰富,主要分为以下几类:数值型函数.字符型函数.日期和时间函数.条件判断函数.系统函数.加密函数以及其他函数.这篇文章只 ...