Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Brighton Meet up: what functional programming means to me.

Functional Brighton Meet up: what functional programming means to me.

Richard Dallaway

September 27, 2011
Tweet

More Decks by Richard Dallaway

Other Decks in Technology

Transcript

  1. happy birthday to me happy birthday to me #lol #omg

    oops #lol oops #lol #omg 㱺 㱺 ⋮ ⋮ What have we have? What do we want?
  2. #lol, #omg & some text Some text 㱺 What have

    we have? What do we want? List[String], String 㱺 String
  3. 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
  4. Option, for comprehensions, flatMap & pattern matching are astonishingly useful

    every day and I’d never heard of them before learning Scala.
  5. 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()) { ...
  6. 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)
  7. 1. Thinking in terms of A 㱺 B 2. Concurrency

    3. Option (& friends) change everything Summary
  8. 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();