


Ben Hutchison: Direct syntax - Make Functional Programming in Scala Fun Again!
Thursday July 17th, Ben Hutchison will lead a discussion about "Direct syntax - Make Functional Programming in Scala Fun Again!"
We'll study the example below, written as a classic for-comprehension and then again, in direct form.
The for-comprehension is burdened with unnecessary boilerplate code, and the if-statement requires noisy, meaningless else branch. The second version using direct syntax is akin to typical non-functional style, as we might see in an object-oriented or imperative language like C#. Did FP just reinvent imperative programming? ... or is there more to the story?
```
def fetchStoreRecord[F[_]: {Async as A, UUIDGen, Session}](id: Long): F[Unit] =
for (status, optRecord) <- queryRecordServer(id)
_ <- if status == 200 && optRecord.isDefined then
for id <- newUUID
_ <- saveRecord(id -> optRecord.get)
yield ()
else A.unit
yield ()
def fetchStoreRecordDirect[F[_]: {Async, UUIDGen, Session}](id: Long): F[Unit] =
async[F]:
val (status, optRecord) = queryRecordServer(id).await
if status == 200 && optRecord.isDefined then
saveRecord(newUUID.await -> optRecord.get).await
```
We'll spend the session understanding what's going on in the above example.
This will take us down a rabbit hole to meet Effectful Values, a key idea in functional programming, and then on to the question of how to express compositions of them. And the rest is just syntax ;)
Arrive from 530pm for conversation & socialising, we'll begin the presentation around 630. We'll probably go for dinner on Lygon st afterwards .
As always, newcomers most welcome. Reach Ben on 0407 990 094 on the night if you have any issues finding the venue.
