Gist: JAVA 8 Stream API: Stream Initialization

Stream represents a sequence of values. Stream API, introduced in JAVA 8 (JSR-355 [1]) enables declarative specification of computation on data. It may also interesting to note that it imposes no restriction on the data source.

Following are the important facts:

  • Stream != Collection
    • It is bound to a data source which can be {collection, array, IO, iterator}
  • Stream does not hold any data
    • It is simply an intermediate data
  • Stream can’t modify its source
    • Good for parallelism.
  • Stream can be infinite.

In this post, we only discuss how to construct a Stream object.

A Stream object can be constructed in the following manner.

    Collection source = /*a collection that will be used as a source of Stream*/; 

Alternatively, Stream contains several builders, as listed below.

  • IntStream: Stream.of(1,3,4)
  • EmptyStream: Stream.empty()
  • InfiniteStream: Stream.iterate(1, n-> n+10)

In the next post, we shall discuss more on how we can use a Stream to specify data transformation in a declarative manner.


[1] JSR-355: Lambda Expression for Java.


Certificate of #ProgFun of @Coursera

Yay! Finally, I have received the certificate of Functional Programming Principles in Scala course. Thanks @coursera! It has been a great pleasure, and I look forward to the future courses (e.g., Discrete Optimization).

progfun certificate

In a previous post, I remember mentioning how awesome this course is, and how much I have enjoyed this course, and looking forward to the next advanced course in this topic. It’s great to know that around 70% students ‘Absolutely’ share the same feeling. So, prof. @oderskey, please hurry up. We are waiting!

Once again, thanks prof. @oderskey and his team for this excellent course.

Retrospective of #ProgFun

Yay! Just finished Functional Programming Principles in Scala (with 100% score :D) instructed by Prof. Martin Odersky et al, at Coursera. It has been an excellent experience due to its great content, amazing teacher, and interesting assignments (e.g., implementing a solver for Bloxorz).

This course focuses on providing a deeper understanding of FP paradigm, and demonstrates how it excels elegantly compare to its contemporaries. Function composition, recursion, pattern matching, concepts of persistent data structures, lazy evaluation are among the few important concepts that have been emphasized and exemplified in the seven weeks of the course. The application of term-rewriting during reduction of expressions and reasoning about it, seemed simply awesome.

Overall, it has been a wonderful experience and I highly recommend it for anyone interested in learning FP paradigm. To motivate further, note that upon successful completion, a certificate from Coursera is provided ;).

Thanks @oderskey, his team, and @coursera for this excellent course, and for this great opportunity. Looking forward to its advanced part.

“Functional Scala” by Mario Gleichmann

"Functional Scala" is a set of tutorials on Scala programming language by Mario Gleichmann. Although a bit verbose, it introduces the key constructs of Scala, and outlines Scala’s primary features from the perspective of functional programming.

Welcome to the first part of a series of episodes about ‘Functional Scala’. While positioning itself as a so called object-functional language, most of the discussion and articles about Scala centered around its object oriented features so far. If you’re reading this, chances are you want to learn more about the functional side of Scala. Well, you’ve come to the right place.

The idea for the following episodes arose out of some talks i gave about ‘Functional Scala’. I decided to write and talk about it because I wanted to solidify my own knowledge about Functional Programming in general and about Scala in particular … and because I thought I could help some people new to Scala to learn its functional features from my perspective.

Not least, there were some critical discussions in the past whether Scala is rightfully characterized as a functional Language. For this to decide, we firstly have to be clear about the core ideas, you’ll regularly come across within widely accepted functional Languages, like Haskell. We’re going to see if and how they are offered in Scala and try to push them to its limits. So without any further ado, let’s enter the world of Functional Programming (FP) in Scala.


“The Neophyte’s Guide to Scala” by Daniel Westheide

This Scala tutorial, called "The Neophyte’s Guide to Scala" can be considered as an auxiliary resource of #progfun. It is particularly good at getting started with Scala, and to delve a bit deeper with it.

From November 2012 to April 2013, I created and published a blog series called , targeted at aspiring Scala enthusiasts who have already made their first steps with the language and are looking for more detailed explanations.