Slide 1

Slide 1 text

Three things I’ve noticed about functional programming while using Scala.

Slide 2

Slide 2 text

happy birthday to me happy birthday to me #lol #omg oops #lol oops #lol #omg 㱺 㱺 ⋮ ⋮ What have we have? What do we want?

Slide 3

Slide 3 text

#lol, #omg & some text Some text 㱺 What have we have? What do we want?

Slide 4

Slide 4 text

#lol, #omg & some text Some text 㱺 What have we have? What do we want? List[String], String 㱺 String

Slide 5

Slide 5 text

def appendTags(tweet: String, tags: List[String]) = tags.foldLeft(tweet) { appendOne } def appendOne(tweet: String, tag: String) = if (tweet contains tag) tweet else tweet+" "+tag

Slide 6

Slide 6 text

“It’s the mutable state, stupid.” – Göetz et al.

Slide 7

Slide 7 text

val results = List(yahoo _, google _).par.map(_.apply)

Slide 8

Slide 8 text

import scala.actors.Futures._ val results = List(yahoo _, google _) map ( f 㱺 future{ f() } ) map (_.apply)

Slide 9

Slide 9 text

Option, for comprehensions, flatMap & pattern matching are astonishingly useful every day and I’d never heard of them before learning Scala.

Slide 10

Slide 10 text

for (int i = 0; i < resultFeed.getEntries().size(); i++) { ContactEntry entry = resultFeed.getEntries().get(i); if (entry.hasName()) { Name name = entry.getName(); if (name.hasFullName()) { ...

Slide 11

Slide 11 text

for { entry ← resultFeed.getEntries name ← Option(entry.getName) full_name ← Option(name.getFullName) birthday ← Option(entry.getBirthday) } yield "%s: %s".format(full_name.getValue, when)

Slide 12

Slide 12 text

1. Thinking in terms of A 㱺 B 2. Concurrency 3. Option (& friends) change everything Summary

Slide 13

Slide 13 text

StringBuffer b = new StringBuffer(tweet); if (tags != null) { for(String tag: tags) { if (tag != null && b.indexOf(tag) == -1) { b.append(tag).append(“ ”); } } } return b.toString();