如何将经典的自定义数据结构用作Java 8流 [英] How To Use Classic Custom Data Structures As Java 8 Streams

查看:104
本文介绍了如何将经典的自定义数据结构用作Java 8流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我看到了一个有关在Java中实现经典链表的 SO问题.显然,这是一个本科生数据结构课程的作业.很容易找到所有语言的列表,树等的问题和实现.

I saw a SO question yesterday about implementing a classic linked list in Java. It was clearly an assignment from an undergraduate data structures class. It's easy to find questions and implementations for lists, trees, etc. in all languages.

我一直在学习Java lambda,并尝试在每一次机会中都使用它们,以使这成语成为我的指尖.这个问题让我感到奇怪:我如何编写一个自定义列表或树,以便可以在所有Java 8 lambda机械中使用它?

I've been learning about Java lambdas and trying to use them at every opportunity to get the idiom under my fingers. This question made me wonder: How would I write a custom list or tree so I could use it in all the Java 8 lambda machinery?

我看到的所有示例都使用内置集合.这些对我有用.我更好奇教授数据结构的教授应该如何重新考虑他们的技术以反映lambda和函数式编程.

All the examples I see use the built in collections. Those work for me. I'm more curious about how a professor teaching data structures ought to rethink their techniques to reflect lambdas and functional programming.

我从Iterator开始,但是它似乎没有完整的功能.

I started with an Iterator,but it doesn't appear to be fully featured.

有人有什么建议吗?

推荐答案

我将查看 http://www.javaslang .io 是一个启发性的库,它确实可以完成您想做的事情:以Java 8方式实现自定义列表,树等.

I'd look at http://www.javaslang.io for inspiration, a library that does exactly what you want to do: Implement custom lists, trees, etc. in a Java 8 manner.

特别是与导入/导出方法之外的JDK集合紧密耦合,但是重新实现了Scala(或其他FP语言)开发人员所期望的所有不变的集合语义.

It specifically doesn't closely couple with the JDK collections outside of importing/exporting methods, but re-implements all the immutable collection semantics that a Scala (or other FP language) developer would expect.

这篇关于如何将经典的自定义数据结构用作Java 8流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆