Implement and test the following:
- Create a stream of the numbers X to Y (where X and Y are Ints)
- Sum the numbers X to Y
- Create a stream of the factorials of X and Y
Implement and test the following:
-
Read at the contents of a text file
-
Use this to read the file
/usr/share/dict/words
for the following: -
Count the words in the file.
-
Count the vowels in the file.
-
Count the words containing a user-supplied substring.
-
Print adjacent pairs of words with the same length (use
source.sliding()
).
-
Write the contents of
medals-expanded.csv
to a collection calledmedals
in a MongoDB database calledolympics
(seeExercise3Setup.scala
) -
Read the medals back in and print them.
-
Traverse the collection and collect the total number of gold, silver, and bronze medals won by each team
-
Traverse the collection and while traversing print the following for each record (use
source.scan()
) :- the number of records read so far;
- the name of the athlete in the current row;
- the number of gold medals they have won so far.
-
Traverse the collection and create a second collection
athletes
containing:- The name of each athlete
- A list of their events
- The number of gold, silver, and bronze medals they've won
Here are the most common methods you'll be using. Use your IDE to find out more about their types.
Where I've used an uppercase first letter, I mean a singleton object from the Akka Streams library. Where I've used a lowercase first letter, I mean a value of the relevant type.
import akka.stream.scaladsl.{Source, FileIO}
// Create a source from a sequence:
Source.apply(iterable)
// Create a source with a single value in it:
Source.single(any)
// Create a source from a file:
FileIO.fromPath(Paths.get(string))
source.map(function)
source.mapConcat(function)
source.mapAsync(int)(function)
source.mapAsyncUnordered(int)(function)
source.flatMapConcat(function)
import akka.stream.scaladsl.Sink
// Create a sink that runs a side-effect for each item:
Sink.foreach(function)
// Create a sink that combines items into a single value:
Sink.fold(any)(function)
// Run a source with a sink:
source.runWith(sink)
// Run a source with a Sink.foreach sink (shorthand):
source.runForeach(function)
// Run a source with a Sink.fold sink (shorthand):
source.runFold(any)(function)