Created
January 5, 2022 12:38
-
-
Save Voltra/0a611263b1c4ade1a277e3166aa9fad5 to your computer and use it in GitHub Desktop.
Magic lambdas in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const DeepProxy = require("proxy-deep") | |
| const _ = new DeepProxy({}, { | |
| _pushOp(op) { | |
| }, | |
| get(target, path, receiver){ | |
| return this.nest(function() {}); | |
| }, | |
| apply(target, thisArg, [obj]){ | |
| return this.path.reduce((currentObj, prop) => { | |
| if(!(currentObj && prop in currentObj)) { | |
| return null; | |
| } | |
| return currentObj[prop]; | |
| }, obj); | |
| }, | |
| }); | |
| const objects = [ | |
| { | |
| entity: { | |
| valid: true, | |
| meta: { | |
| name: "name", | |
| description: "description", | |
| }, | |
| }, | |
| }, | |
| { | |
| entity: { | |
| valid: false, | |
| meta: { | |
| name: "my Name", | |
| description: "My description", | |
| }, | |
| }, | |
| }, | |
| ]; | |
| objects | |
| .map(_.entity) | |
| .filter(_.valid) | |
| .map(_.meta.name) | |
| .forEach(x => console.log(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment