flatMappy bird follow up material

A huge thanks to everybody who attended my talk at Scala eXchange 2016, "flatMappy bird: functional flappy bird".

The aim of my talk was to give:

  • A feeling for how FRP, and Coroutines work
  • Pride in functional programming
  • A couple of hints about what to look at if it peaked your interest

Here are a few things to point you towards the latter!

Coroutines

The flatMappy bird project was based on 2 articles:

As you can probably guess, I found these absolutely fascinating - and I highly recommend you check them out!

There is also a Scala Coroutines library. I have not tried to build anything with this yet, but the documentation looks great - and it's fully featured. Definitely worth a look.

Episode 7 of Breakpoint Radio also has some great discussion of Coroutine development in Scala and on the JVM.

Scala.js

The place to go is Li Haoyi's Hands on Scala.js. Whilst you're there, check out the rest of his website - it's a treasure trove.

flatMappy bird itself

A challenge

Implement "Hello World" with a Coroutine yourself, to understand the concept:

Problem
There is a time varying String value that we can sample. We want to transform it to a time varying Boolean:
  • The latest value of the String is "World" AND
  • The previous value of the String was "Hello"

Here's some code to get you started:

trait CoRoutine[A, B] {
  def apply(input: A): (B, CoRoutine[A, B])
}

val helloWorld: CoRoutine[String, Boolean] = ???

val (res1, next1) = helloWorld("Hello")
println(res1) // should print false

val (res2, next2) = next1("World")
println(res2) // should print true

val (res3, next3) = next2("Foo")
println(res3) // should print false

This will be easy if you read Generalizing streams into Coroutines.

Enjoy!

Written on December 7, 2016