StreamEx 0.6.2 Enhancing Java 8 Streams.

StreamEx是一个Java库,旨在通过提供更多实用方法来增强Java 8的流API。该库完全兼容Java 8流,并提供更简洁的常用任务处理方式。它包括四个主要类:StreamEx、IntStreamEx、LongStreamEx和DoubleStreamEx,以及EntryStream类用于处理映射条目的流。此外,还提供了一些新的收集器。StreamEx支持更好的旧代码互操作性、并行处理友好性和高性能。

source: https://github.com/amaembo/streamex


StreamEx 0.6.2

Enhancing Java 8 Streams.

Maven Central Build Status Coverage Status

This library defines four classes: StreamExIntStreamExLongStreamExDoubleStreamEx which are fully compatible with Java 8 stream classes and provide many additional useful methods. Also EntryStream class is provided which represents the stream of map entries and provides additional functionality for this case. Finally there are some new useful collectors defined in MoreCollectors class as well as primitive collectors concept.

Full API documentation is available here.

Take a look at the Cheatsheet for brief introduction to the StreamEx!

Before updating StreamEx check the migration notes and full list of changes.

StreamEx library main points are following:

  • Shorter and convenient ways to do the common tasks.
  • Better interoperability with older code.
  • 100% compatibility with original JDK streams.
  • Friendliness for parallel processing: any new feature takes the advantage on parallel streams as much as possible.
  • Performance and minimal overhead. If StreamEx allows to solve the task using less code compared to standard Stream, it should not be significantly slower than the standard way (and sometimes it's even faster).

Examples

Collector shortcut methods (toList, toSet, groupingBy, joining, etc.)

List<String> userNames = StreamEx.of(users).map(User::getName).toList();
Map<Role, List<User>> role2users = StreamEx.of(users).groupingBy(User::getRole);
StreamEx.of(1,2,3).joining("; "); // "1; 2; 3"

Selecting stream elements of specific type

public List<Element> elementsOf(NodeList nodeList) {
    return IntStreamEx.range(nodeList.getLength())
      .mapToObj(nodeList::item).select(Element.class).toList();
}

Adding elements to stream

public List<String> getDropDownOptions() {
    return StreamEx.of(users).map(User::getName).prepend("(none)").toList();
}

public int[] addValue(int[] arr, int value) {
    return IntStreamEx.of(arr).append(value).toArray();
}

Removing unwanted elements and using the stream as Iterable:

public void copyNonEmptyLines(Reader reader, Writer writer) throws IOException {
    for(String line : StreamEx.ofLines(reader).remove(String::isEmpty)) {
        writer.write(line);
        writer.write(System.lineSeparator());
    }
}

Selecting map keys by value predicate:

Map<String, Role> nameToRole;

public Set<String> getEnabledRoleNames() {
    return StreamEx.ofKeys(nameToRole, Role::isEnabled).toSet();
}

Operating on key-value pairs:

public Map<String, List<String>> invert(Map<String, List<String>> map) {
    return EntryStream.of(map).flatMapValues(List::stream).invert().grouping();
}

public Map<String, String> stringMap(Map<Object, Object> map) {
    return EntryStream.of(map).mapKeys(String::valueOf)
        .mapValues(String::valueOf).toMap();
}

Map<String, Group> nameToGroup;

public Map<String, List<User>> getGroupMembers(Collection<String> groupNames) {
    return StreamEx.of(groupNames).mapToEntry(nameToGroup::get)
        .nonNullValues().mapValues(Group::getMembers).toMap();
}

Pairwise differences:

DoubleStreamEx.of(input).pairMap((a, b) -> b-a).toArray();

Support of byte/char/short/float types:

short[] multiply(short[] src, short multiplier) {
    return IntStreamEx.of(src).map(x -> x*multiplier).toShortArray(); 
}

Define custom lazy intermediate operation recursively:

static <T> StreamEx<T> scanLeft(StreamEx<T> input, BinaryOperator<T> operator) {
        return input.headTail((head, tail) -> scanLeft(tail.mapFirst(cur -> operator.apply(head, cur)), operator)
                .prepend(head));
}

And more!

License

This project is licensed under Apache License, version 2.0

Installation

Releases are available in Maven Central

Before updating StreamEx check the migration notes and full list of changes.

To use from maven add this snippet to the pom.xml dependencies section:

<dependency>
  <groupId>one.util</groupId>
  <artifactId>streamex</artifactId>
  <version>0.6.2</version>
</dependency>

Pull requests are welcome.


### 解决安装依赖时找不到 Lua 头文件 `lua.h` 的问题 在使用 LuaRocks 安装 Lua 模块时,如果出现类似 `Failed finding Lua header files` 的错误,通常是因为 Lua 的头文件路径未正确配置。以下是一些可能的解决方案: #### 1. 确保 Lua 开发包已安装 Lua 的头文件(如 `lua.h`)通常包含在 Lua 的开发包中。如果没有安装 Lua 的开发包,编译器将无法找到这些文件。可以通过以下命令检查是否已安装 Lua 开发包,并根据需要进行安装[^1]。 对于基于 Debian 的系统(如 Ubuntu),可以运行以下命令: ```bash sudo apt-get install lua5.4-dev ``` 对于基于 RedHat 的系统(如 CentOS),可以运行以下命令: ```bash sudo yum install lua-devel ``` #### 2. 配置正确的头文件路径 如果 Lua 的头文件已经安装,但仍然出现 `Failed finding Lua header files` 错误,可能是 LuaRocks 未能正确找到头文件路径。可以通过设置环境变量 `LUA_INCDIR` 来指定 Lua 的头文件路径[^1]。 例如,如果 Lua 的头文件位于 `/usr/local/include/lua5.4`,可以运行以下命令: ```bash export LUA_INCDIR=/usr/local/include/lua5.4 luarocks install <module_name> ``` #### 3. 使用 `--with-lua-include` 参数(不推荐) 尽管官方文档建议使用 `--with-lua-include` 参数来指定 Lua 的头文件路径,但在某些情况下,这可能会导致路径配置错误。因此,建议优先通过环境变量 `LUA_INCDIR` 来指定路径[^1]。 #### 4. 检查 LuaRocks 的配置文件 确保 LuaRocks 的配置文件中正确设置了 Lua 的路径。在 Windows 系统中,可以参考以下路径设置[^2]: ```plaintext LUA_PATH=C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program Files(x86)\LuaRocks\lua\?\init.lua;%LUA_DIR%\share\lua\5.1\?.lua;%LUA_DIR%\share\lua\5.1\?\init.lua;%LUA_DIR%\lib\luarocks\rocks\cwrap\scm-1\lua\torchcwrap.lua ``` 在 Linux 或 macOS 系统中,可以检查 LuaRocks 的配置文件(通常是 `~/.luarocks/config.lua`),确保其中的 `paths` 设置正确。 #### 5. 卸载并重新安装相关模块 如果上述方法均无效,可以尝试卸载并重新安装相关模块。例如,如果问题是由于版本冲突引起的,可以参考以下命令卸载并重新安装特定版本的模块[^3]: ```bash npm uninstall vue-router npm i vue-router@3.5.2 ``` 虽然此命令与 Lua 无直接关系,但它展示了如何通过卸载和重新安装来解决依赖问题。 --- ### 示例代码:手动指定 Lua 头文件路径 如果需要手动指定 Lua 的头文件路径,可以参考以下步骤: ```bash # 假设 Lua 的头文件位于 /usr/local/include/lua5.4 export LUA_INCDIR=/usr/local/include/lua5.4 # 安装 Lua 模块 luarocks install <module_name> ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值