What functional programming means to me

  • 1,799 views
Uploaded on

The assignment for Functional Brighton Meet up was to describe what functional programming means to you...

The assignment for Functional Brighton Meet up was to describe what functional programming means to you...

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,799
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
17
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Three things I’ve noticed aboutfunctional programming while using Scala.
  • 2. What have we have? What do we want? happy birthday tohappy birthday to me me #lol #omg oops #lol oops #lol #omg ⋮ ⋮
  • 3. What have we have? What do we want? #lol, #omg Some text & some text
  • 4. What have we have? What do we want? #lol, #omg Some text & some text List[String], String String
  • 5. 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
  • 6. 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();
  • 7. “It’s the mutable state, stupid.” – Göetz et al.
  • 8. val results = List(yahoo _, google _).par.map(_.apply)
  • 9. import scala.actors.Futures._val results = List(yahoo _, google _) map ( f future{ f() } ) map (_.apply)
  • 10. Option, for comprehensions,flatMap & pattern matching are astonishingly useful every day and I’d never heard of them before learning Scala.
  • 11. 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()) {        ...  
  • 12. 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) 
  • 13. Summary1. Thinking in terms of A B2. Concurrency3. Option (& friends) change everything