SlideShare a Scribd company logo
taming errors with
                             FunctionalKit




Tuesday 24 March 2009
Error handling in Obj-C



      ‣ nil
      ‣ NSError
      ‣ @throw, and others?


Tuesday 24 March 2009
nil



Tuesday 24 March 2009
‣      MyObject *object = [dictionary
             objectForKey:@”key”]; // Object might be nil.

      ‣      [object doSomething] => nil




Tuesday 24 March 2009
Pros
                         Easy to ignore
                        Safe messaging




Tuesday 24 March 2009
Cons
                                      Easy to ignore
                                    ‘Safe’ messaging
                          Variadic functions (nil termination)
                        Not in the Type - When do you get nils?
                            You don’t have to think about it
                                   No error message



Tuesday 24 March 2009
NSError



Tuesday 24 March 2009
‣      NSError *error;

      ‣      id val = [something withObject:object error:&error];

      ‣      if (!error) { ... } else { ... }

      ‣      Or just use val directly.




Tuesday 24 March 2009
Pros
                              Easy to ignore
                            Failure messages
                        Clear to the API consumer




Tuesday 24 March 2009
Cons
                            (Arguably) dirtier code
                          (Arguably) dirtier selectors
                        I don’t like output parameters
                                  Mutable state




Tuesday 24 March 2009
So...



Tuesday 24 March 2009
Fancy Functional
                        Types


Tuesday 24 March 2009
nil → Option



Tuesday 24 March 2009
Option - A better nil
                            It fails when messaged
                                explicit handling




Tuesday 24 March 2009
single value array



Tuesday 24 March 2009
Some value



Tuesday 24 March 2009
Or none.



Tuesday 24 March 2009
Getting an Option



      ‣      + (FKOption *)fromNil:(id)maybeNil;

      ‣      + (FKOption *)fromNil:(id)maybeNil ofType:(Class)cls;

      ‣      + (FKOption *)some:(id)value;

      ‣      + (FKOption *)none;




Tuesday 24 March 2009
Using an Option



      ‣      - @property (readonly) BOOL isSome;

      ‣      - @property (readonly) BOOL isNone;

      ‣      - @property (readonly) id some;

      ‣      - (id)orSome:(id)some;




Tuesday 24 March 2009
The Code




Tuesday 24 March 2009
(value|NSError) →
                      Either


Tuesday 24 March 2009
Getting an Either




      ‣      + (FKEither *)eitherWithRight:(id)value;

      ‣      + (FKEither *)eitherWithLeft:(id)value;




Tuesday 24 March 2009
Using an Either



      ‣      @property (readonly) FKRightProjection *right;

      ‣      @property (readonly) FKLeftProjection *left;

      ‣      @property (readonly) BOOL isLeft;

      ‣      @property (readonly) BOOL isRight;




Tuesday 24 March 2009
Using a Left/Right



      ‣      @property (readonly) id *value;

      ‣      @property (readonly) id valueOrOther:(id)value;

      ‣      - (id)valueOrFailWithMessage:(NSString *)message;




Tuesday 24 March 2009
‘Wrong’ on Left
                        ‘Right’ on Right


Tuesday 24 March 2009
The Code




Tuesday 24 March 2009
Is it better?



Tuesday 24 March 2009
Still have to extract.
         Can still be noisy.


Tuesday 24 March 2009
List of As



  map:: (a→b)→[a]→[b]
                                                   List of Bs
                   Function from A to B



Tuesday 24 March 2009
Mapping with Option



      ‣      - (FKOption *)mapWithSelector:(SEL)selector;

      ‣      - (FKOption *)mapWithSelector:(SEL)selector onObject:
             (id)object;




Tuesday 24 March 2009
The Code




Tuesday 24 March 2009
Mapping with Either



      ‣      - (FKEither *)mapWithSelector:(SEL)selector;

      ‣      - (FKEither *)mapWithSelector:(SEL)selector onObject:
             (id)object;




Tuesday 24 March 2009
The Code




Tuesday 24 March 2009
The Code



                        OR



                        OR




Tuesday 24 March 2009
By the way...



Tuesday 24 March 2009
Option is a Monad.



Tuesday 24 March 2009
Either is a Monad
                        too.


Tuesday 24 March 2009
FunctionalKit
                 http://github.com/mogeneration/functionalkit




Tuesday 24 March 2009
FunctionalKit

      ‣      FKOption

      ‣      FKEither

      ‣      FKFunction (a->b)

      ‣      FKEffect (a -> Nothing)

      ‣      FKP*

      ‣      FKNewtype

      ‣      FKMacros



Tuesday 24 March 2009
resources
           http://github.com/mogeneration/
                      functionalkit
      http://www.qconlondon.com/london-2009/
      presentation/Null+References:+The+Billion
                    +Dollar+Mistake



Tuesday 24 March 2009

More Related Content

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Taming Errors with FunctionalKit

  • 1. taming errors with FunctionalKit Tuesday 24 March 2009
  • 2. Error handling in Obj-C ‣ nil ‣ NSError ‣ @throw, and others? Tuesday 24 March 2009
  • 4. MyObject *object = [dictionary objectForKey:@”key”]; // Object might be nil. ‣ [object doSomething] => nil Tuesday 24 March 2009
  • 5. Pros Easy to ignore Safe messaging Tuesday 24 March 2009
  • 6. Cons Easy to ignore ‘Safe’ messaging Variadic functions (nil termination) Not in the Type - When do you get nils? You don’t have to think about it No error message Tuesday 24 March 2009
  • 8. NSError *error; ‣ id val = [something withObject:object error:&error]; ‣ if (!error) { ... } else { ... } ‣ Or just use val directly. Tuesday 24 March 2009
  • 9. Pros Easy to ignore Failure messages Clear to the API consumer Tuesday 24 March 2009
  • 10. Cons (Arguably) dirtier code (Arguably) dirtier selectors I don’t like output parameters Mutable state Tuesday 24 March 2009
  • 12. Fancy Functional Types Tuesday 24 March 2009
  • 13. nil → Option Tuesday 24 March 2009
  • 14. Option - A better nil It fails when messaged explicit handling Tuesday 24 March 2009
  • 15. single value array Tuesday 24 March 2009
  • 16. Some value Tuesday 24 March 2009
  • 17. Or none. Tuesday 24 March 2009
  • 18. Getting an Option ‣ + (FKOption *)fromNil:(id)maybeNil; ‣ + (FKOption *)fromNil:(id)maybeNil ofType:(Class)cls; ‣ + (FKOption *)some:(id)value; ‣ + (FKOption *)none; Tuesday 24 March 2009
  • 19. Using an Option ‣ - @property (readonly) BOOL isSome; ‣ - @property (readonly) BOOL isNone; ‣ - @property (readonly) id some; ‣ - (id)orSome:(id)some; Tuesday 24 March 2009
  • 20. The Code Tuesday 24 March 2009
  • 21. (value|NSError) → Either Tuesday 24 March 2009
  • 22. Getting an Either ‣ + (FKEither *)eitherWithRight:(id)value; ‣ + (FKEither *)eitherWithLeft:(id)value; Tuesday 24 March 2009
  • 23. Using an Either ‣ @property (readonly) FKRightProjection *right; ‣ @property (readonly) FKLeftProjection *left; ‣ @property (readonly) BOOL isLeft; ‣ @property (readonly) BOOL isRight; Tuesday 24 March 2009
  • 24. Using a Left/Right ‣ @property (readonly) id *value; ‣ @property (readonly) id valueOrOther:(id)value; ‣ - (id)valueOrFailWithMessage:(NSString *)message; Tuesday 24 March 2009
  • 25. ‘Wrong’ on Left ‘Right’ on Right Tuesday 24 March 2009
  • 26. The Code Tuesday 24 March 2009
  • 27. Is it better? Tuesday 24 March 2009
  • 28. Still have to extract. Can still be noisy. Tuesday 24 March 2009
  • 29. List of As map:: (a→b)→[a]→[b] List of Bs Function from A to B Tuesday 24 March 2009
  • 30. Mapping with Option ‣ - (FKOption *)mapWithSelector:(SEL)selector; ‣ - (FKOption *)mapWithSelector:(SEL)selector onObject: (id)object; Tuesday 24 March 2009
  • 31. The Code Tuesday 24 March 2009
  • 32. Mapping with Either ‣ - (FKEither *)mapWithSelector:(SEL)selector; ‣ - (FKEither *)mapWithSelector:(SEL)selector onObject: (id)object; Tuesday 24 March 2009
  • 33. The Code Tuesday 24 March 2009
  • 34. The Code OR OR Tuesday 24 March 2009
  • 35. By the way... Tuesday 24 March 2009
  • 36. Option is a Monad. Tuesday 24 March 2009
  • 37. Either is a Monad too. Tuesday 24 March 2009
  • 38. FunctionalKit http://github.com/mogeneration/functionalkit Tuesday 24 March 2009
  • 39. FunctionalKit ‣ FKOption ‣ FKEither ‣ FKFunction (a->b) ‣ FKEffect (a -> Nothing) ‣ FKP* ‣ FKNewtype ‣ FKMacros Tuesday 24 March 2009
  • 40. resources http://github.com/mogeneration/ functionalkit http://www.qconlondon.com/london-2009/ presentation/Null+References:+The+Billion +Dollar+Mistake Tuesday 24 March 2009

Editor's Notes