What functional programming means to me

1,993 views
1,918 views

Published on

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,993
On SlideShare
0
From Embeds
0
Number of Embeds
1,323
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

What functional programming means to me

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

×