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

Fun with Types

Fun with Types

Talk given at The Developers Conference in Sao Paulo, 2014 in the Scala track

Breno Ferreira

August 08, 2014
Tweet

More Decks by Breno Ferreira

Other Decks in Programming

Transcript

  1. FOR EXAMPLE d e f d i v ( x

    : I n t , y : I n t ) = x / y
  2. FOR EXAMPLE: v a l s j o b s

    : ( ) = > S t r i n g s j o b s ( ) / / : " A p p l e I " s j o b s ( ) / / : " A p p l e I I " s j o b s ( ) / / : " M a c i n t o s h ! " s j o b s ( ) / / : " ✗"
  3. FOR EXAMPLE: v a l s j o b s

    : ( ) = > S t r i n g s j o b s ( ) / / : " i P h o n e " s j o b s ( ) / / : " i P a d " s j o b s ( ) / / : " i C l o u d " s j o b s ( ) / / : " ✝"
  4. WHAT ABOUT A GETTER OF GETTERS? ( ) = >

    ( ) = > T r y [ O p t i o n [ T ] ]
  5. EXTRACT TO INTERFACE t r a i t I t

    e r a b l e [ T ] { g e t I t e r a t o r : I t e r a t o r [ T ] } t r a i t I t e r a t o r [ T ] { h a s N e x t : B o o l e a n n e x t : T }
  6. ASYNC GETTER ( ( T r y [ T ]

    ) = > ( ) ) = > ( )
  7. BASICALLY, A FUTURE t r a i t F u

    t u r e [ T ] { o n S u c c e s s : T = > ( ) o n F a i l u r e : E x c e p t i o n = > ( ) }
  8. EASY: ( ( T r y [ I t e

    r a b l e [ T ] ] ) = > ( ) ) = > ( )
  9. BETTER: ( ( T r y [ O p t

    i o n [ T ] ] ) = > ( ) ) = > ( )
  10. OBSERVABLE/OBSERVER t r a i t O b s e

    r v a b l e [ T ] { s u b s c r i b e ( o b s e r v e r : O b s e r v e r [ T ] ) } t r a i t O b s e r v e r [ T ] { o n N e x t ( v a l u e : T ) o n E r r o r ( e r r o r : E x c e p t i o n ) o n C o m p l e t e d ( ) }
  11. FOUR BASIC EFFECTS IN COMPUTING: One Many Sync T /

    Option[T] Iterable[T] Async Future[T] Observable[T]
  12. Q&A