java简单的函数_一个java快速简单轻量级高阶函数库

HFunc

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f74616e677869616f6c762f6d6176656e2f6866756e632f696d616765732f646f776e6c6f61642e737667

English | 中文

A fast and simple Java Higher-order function lib. Support serial compute and parallel compute. Applies to Java and Android.

Support

map

filter

reduce

Gradle

dependencies {

compile 'com.library.tangxiaolv:hfunc:1.0.1'

}

Guide

Example:

//data collection

List c = new ArrayList<>();

for (int i = 1; i < 101; i++) {

c.add(i);

}

c8475acd82a15dc81f2d5e0b565d4a5c.png

serial compute: 1078ms

List result = HFunc.map(c, new HFunc.Func1() {

@Override

public String call(Integer item) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return Integer.toString(item * 2);

}

});

parallel compute: 150ms

List result = HFunc.mapParallel(c, new HFunc.Func1() {

@Override

public String call(Integer item) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return Integer.toString(item * 2);

}

});

filter:

0891a389d8afb5b1cc874be9278d3a71.png

serial compute: 1037ms

List result = HFunc.filter(c, new HFunc.Func1() {

@Override

public Boolean call(Integer item) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return item % 2 != 0;

}

});

parallel compute: 159ms

List result = HFunc.filterParallel(c, new HFunc.Func1() {

@Override

public Boolean call(Integer item) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return item % 2 != 0;

}

});

2d8047c06d1c166c13207c92bf1ed626.png

serial compute: 1061ms

Integer result = HFunc.reduce(c, new HFunc.Func2() {

@Override

public Integer call(Integer merge, Integer next) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return merge + next;

}

});

parallel compute: 239ms

Integer result = HFunc.reduceParallel(c, new HFunc.Func2() {

@Override

public Integer call(Integer merge, Integer next) {

try {

Thread.sleep(10);

} catch (InterruptedException e) {}

return merge + next;

}

});

LICENSE

Copyright 2016 XiaoLv Tang

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值