Skip to content

Commit

Permalink
增加ramda目录
Browse files Browse the repository at this point in the history
  • Loading branch information
navono committed Aug 5, 2017
1 parent 19633c1 commit c601eb2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
File renamed without changes.
55 changes: 55 additions & 0 deletions Ramda/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const R = require('ramda');

// 测试输出
const out = i => console.log(i);

// let sub = R.reduce(R.subtract, 0);
// R.compose(out, sub)([1, 2, 3]);

// 在不增加函数的情况,使用 isEven 查找第一个奇数
// complement 可以对函数返回值取反,接受一个函数 f ,返回一个新函数 g
// const isEven = x => x % 2 === 0;
// let find = R.find(R.complement(isEven));
// R.compose(out, find)([1, 2, 3, 4]);


// const gt10 = x => x > 10;
// const even = x => x % 2 === 0;
// const gt20 = x => x > 20;
// var f = R.either(even, gt20, gt10);
// R.compose(out, f)(17);


const multiply = (a, b) => a * b
const addOne = x => x + 1
const square = x => x * x

// const operate = (x, y) => {
// const product = multiply(x, y)
// const incremented = addOne(product)
// const squared = square(incremented)

// return squared
// }

// also like
// cosnt operate = (x, y) => square(addOne(multiply(x, y)));

// from left to right
// const operate = R.pipe(
// multiply,
// addOne,
// square
// )

// from right to left
const operate = R.compose(
square,
addOne,
multiply
);

// 有个用法是,定义函数的时候,使用 pipe,调用函数的时候,使用 compose

R.compose(out, operate)(3, 4) ;

22 changes: 12 additions & 10 deletions echarts/twoGrid.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
devtool: 'source-map',
// entry: path.resolve(__dirname, './react/components/HOC/index.js'),
// entry: path.resolve(__dirname, './echarts/twoGrid.js'),
entry: path.resolve(__dirname, './echarts/dynamicData.js'),
entry: path.resolve(__dirname, './echarts/multipleX.js'),
// entry: path.resolve(__dirname, './echarts/dynamicData.js'),
output: {
filename: '[name].js',
path: path.resolve(__dirname, './build')
Expand Down

0 comments on commit c601eb2

Please sign in to comment.