asgc-streamapi

0.0.1 • Public • Published

欢迎使asgc-streamapi

asgc-streamapi是傲世孤尘开源的一个基于lambda的集合操作库,它类似于java的Stream API.


如何使用asgc-streamapi

1、安装模块

npm install asgc-streamapi

2、引入模块

var api = require('asgc-streamapi');

3、初识asgc-streamapi

var api = require('asgc-streamapi');  
 
 
var Stream = api.Stream;
var Collectors = api.Collectors;
var Collector = api.Collector;
 
var ret;
 
console.log('求1到100间的奇数项之和:');
Stream.rangeClose(1,100).filter(n => n % 2 === 1).out(Collectors.sum());
 
console.log('将已知数组中下标为偶数的项*2得到一个新的数组:');
ret = [2,3,54,6,7,8,9,9,90,23,45].stream().filter(n => n % 2 === 0).map(n => n * 2).out(Collectors.toArray());
 
console.log('输出斐波那契数列前10项:');
Stream.recursive([1,1],(n,a,b) => a + b).limit(10).forEach(console.log);
 
console.log('输出1、4、9、16、25...数列前10项:');
Stream.recursive([],n => n * n).filter(n => n > 0).limit(10).out(Collectors.toArray());
 
console.log('输出九九乘法表:')
Stream.rangeClose(1,9).map(a => Stream.rangeClose(1,9).filter(b => b <= a).map(b => a + ' * ' + b + ' = ' + (* b)).collect(Collectors.join('\t'))).out(Collectors.join('\n'));
 
console.log('输出1到10的阶乘结果:')
Stream.recursive([1],(n,a) => (+ 1) * a).limit(10).out(Collectors.toArray());
 
 
 

3.1、输出结果

求1到100间的奇数项之和:
2500
将已知数组中下标为偶数的项*2得到一个新的数组:
[ 4, 108, 12, 16, 180 ]
输出斐波那契数列前10项:
1
1
2
3
5
8
13
21
34
55
输出1、4、9、16、25...数列前10项:
[ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ]
输出九九乘法表:
1 * 1 = 1
2 * 1 = 2	2 * 2 = 4
3 * 1 = 3	3 * 2 = 6	3 * 3 = 9
4 * 1 = 4	4 * 2 = 8	4 * 3 = 12	4 * 4 = 16
5 * 1 = 5	5 * 2 = 10	5 * 3 = 15	5 * 4 = 20	5 * 5 = 25
6 * 1 = 6	6 * 2 = 12	6 * 3 = 18	6 * 4 = 24	6 * 5 = 30	6 * 6 = 36
7 * 1 = 7	7 * 2 = 14	7 * 3 = 21	7 * 4 = 28	7 * 5 = 35	7 * 6 = 42	7 * 7 = 49
8 * 1 = 8	8 * 2 = 16	8 * 3 = 24	8 * 4 = 32	8 * 5 = 40	8 * 6 = 48	8 * 7 = 56	8 * 8 = 64
9 * 1 = 9	9 * 2 = 18	9 * 3 = 27	9 * 4 = 36	9 * 5 = 45	9 * 6 = 54	9 * 7 = 63	9 * 8 = 72	9 * 9 = 81
输出1到10的阶乘结果:
[ 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800 ]

asgc-callback相关

asgc-operator

asgc-lisen是傲世孤尘开源的一个运算符定义工具,它内置了一些常见的数学运算(+、-、*、/、...),并且通过接口可以扩展我们自己的运算符,带来前所未有的编程体验。

asgc-observer

asgc-observer是傲世孤尘开源的一个面向事件、消息编程的库。

asgc-web

asgc-web是傲世孤尘开源的一个nodejs web容器,mvc框架。实现了后端路由、请求分发、参数解析、前端模板渲染等等。

联系我们

笔者QQ 1052045476 nodejs交流群 527393872 java交流群 527393872 c/c++语言交流群 251975693

Readme

Keywords

none

Package Sidebar

Install

npm i asgc-streamapi

Weekly Downloads

0

Version

0.0.1

License

ISC

Unpacked Size

11.4 kB

Total Files

7

Last publish

Collaborators

  • aoshiguchen