Last active
August 9, 2017 17:14
-
-
Save mkamakura/a5e75ff6ea74b6e57473c0cab291c69d to your computer and use it in GitHub Desktop.
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 filter = require('lodash/fp/filter') | |
const map = require('lodash/fp/map') | |
const flow = require('lodash/fp/flow') | |
const omit = require('lodash/fp/omit') | |
const trim = require('lodash/fp/trim') | |
const get = require('lodash/fp/get') | |
const getOr = require('lodash/fp/getOr') | |
const has = require('lodash/fp/has') | |
const transform = require('lodash/fp/transform') | |
const arr = [1, 2, 3, 4, 5] | |
console.log(filter((v) => v > 3)(arr)) | |
// => [ 4, 5 ] | |
console.log(map((v) => v + 1)(arr)) | |
// => [ 2, 3, 4, 5, 6 ] | |
console.log( | |
flow( | |
filter((v) => v > 3), | |
map((v) => v + 1) | |
)(arr) | |
) | |
// => [ 5, 6 ] | |
const obj = { | |
red: 'apple', | |
blue: 'sky', | |
yellow: 'warning', | |
green: 'leaf' | |
} | |
console.log(omit('blue')(obj)) | |
// => { red: 'apple', yellow: 'warning', green: 'leaf' } | |
const name = ' mkamakura ' | |
console.log(trim(name)) | |
// => mkamakura | |
const nestedObj = { | |
hoge: { | |
foo: { | |
bar: 1 | |
} | |
} | |
} | |
console.log(get('hoge.foo.bar')(nestedObj)) | |
// => 1 | |
console.log(get('hoge.foo.bar.aaa')(nestedObj)) | |
// => undefined | |
console.log(getOr(1)('hoge.foo.bar.aaa')(nestedObj)) | |
// => 1 | |
console.log(has('hoge.foo.bar')(nestedObj)) | |
// => true | |
console.log(has('hoge.foo.bar.aaa')(nestedObj)) | |
// => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment