java8 Stream和Lisp对比

java8支持了函数式编程,lisp中最基本的元素就是list,car,cdr,cons


1.(car list)取出头


list.stream().findFirst().get()


2. (cdr list) 取出除头部外


list.stream().skip(1)


3. (cons x list) 


Stream.concat(Stream.of(x), list.stream())


java8构造Infinite Stream


Stream.iterate(1, i -> i + 2).filter(i -> i > 250).skip(10).limit(10)

Stream.generate…


注意不要用distinct,distinct不知道怎么和interate集成使用


http://stackoverflow.com/questions/22483554/how-to-create-an-infinite-stream-with-java-8

http://blog.jooq.org/2014/06/13/java-8-friday-10-subtle-mistakes-when-using-the-streams-api/

http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html


一个问题:http://stackoverflow.com/questions/20470010/collect-successive-pairs-from-a-stream


将[1,2,3,4,5] => [[1,2], [2,3], [3,4], [4,5]]

    原文作者:kiwi小白
    原文地址: https://blog.csdn.net/kiwi_coder/article/details/49003527
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞