Technical Setup
A great way to learn fs2 is to use ammonite (a scala repl). Ammonite allows you to keep a list of scala expressions and dependent libraries in a separate scala file and import them.
I keep a set of imports around that I include when needed:
You can also use latest.version
or latest.release
instead of an explicit version number such as 0.9.1
. With this .sc
file you can just run the console:
then run the command to lead the imports:
Notice the prompt change via the fs2.sc file so you know what you imported. You can now easily access fs2 and the imports present in the myfs2.sc
will be available in your repl session. This is due to the use of "$exec" versus "$file" in amm.
If you use the scala-ide in eclipse, you can also open a scala worksheet and have the outputs automatically appended to the end of the scala code lines. This is an alternative to using the sbt console. The scala worksheet output looks different than the raw REPL (note this still shows scalaz-streams):
You may also be able to get a scala notebook interface running using jyputer or another notebook implementation.
The Async[Task]
brings an implicit Async strategy design object into implicit scope. It can be used to abstractly provide asynchronous building blocks without committing to a particular effect. fs2 uses this through the library to provide capabilities independent of the effect. There is an implicit in Task's companion object which can be imported using import Task._
.
Last updated