A collect function is a method that takes a Partial Function as its parameter and applies it to all the elements in the collection to create a new collection which satisfies the Partial Function.
To understand its utility imagine the following scenario :
Given a DataStream that produces events of type Purchase and View
Transform this stream into a stream of purchase amounts over 1000 euros.
Currently an implementation might look like
Or alternatively you could do this
But with collect implemented it could look like
Which is a lot nicer to both read and write