
Sure, there’s a lot going on in this function. In our case, we expect to return a List of the Mammal type or the subtype of Mammal. Type parameter used in the return type: We expect to return a List of type T, or whatever we end up passing in as T.Whatever we pass in as T is designated by the type parameter declaration, if there is one. Type parameter used in the receiver type: This function is an extension function for a List of type T.This is what bounded type parameters are for. For example, this method only wants to accept instances of Mammal or its subtypes. There may be times when you want to restrict the types that can be used as type arguments in a parameterized type. Type parameter declaration: In order to use a generic method as an ordinary method, you must specify a type between angle brackets.Stream.forEach(::println) // Error:: This sequence can be consumed only once. Val someList = items.asSequence().filter Then you can use toList(), toSet(), toMap() or some other function to materialize the Sequence at the end. At the end of the chain of functions, you usually end up with a Sequence as well. If you want to lazy process a chain, you can convert to a Sequence using asSequence() before the chain. Partition students into passing and failing.How streams work - filter, upper case, then sort a list.Group names of members in roster by gender.Different Kinds of Streams #7 - lazily iterate Doubles, map to Int, map to String, print each.Different Kinds of Streams #6 - lazily iterate a stream of Ints, map the values, print results.


Different Kinds of Streams #1 - eager using first item if it exists.Counting items in a list after filter is applied.Convert elements to strings and concatenate them, separated by commas.Collect example #7b - Collect with SummarizingInt.Collect example #7a - Map names, join together with delimiter.Collect example #6 - group people by age, print age and names together.

