SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
W I T C H C R A F T
M O N A D S F O R T H E W O R K I N G A L C H E M I S T
W I T C H C R A F T
M O N A D S F O R T H E W O R K I N G A L C H E M I S T
L O T S O F S T U F F
A B O U T T H I S TA L K
• The Witchcraft suite: easier algebraic code for Elixir
• Don’t need to know Haskell/Idris/PureScript/cat theory, but it helps
• Throwing a lot at you (sorry)
• Only covering a subset of what’s in these libraries
• One takeaway:
B R O O K LY N Z E L E N K A
• @expede
• Founding partner at Robot Overlord
• Runs the Vancouver Functional Programming 

and Vancouver Erlang/Elixir Meetups
• Author of Witchcraft, TypeClass, Algae, Quark, Exceptional, and others
• I have Witchcraft stickers (come see me afterwards)
W H AT ’ S I N A N A M E ?
witchcraft noun /ˈwɪtʃˌkrɑːft/
1. the art or power of bringing magical or preternatural power to bear or
the act or practice of attempting to do so
2. the influence of magic or sorcery
3. fascinating or bewitching influence or charm
4. an Elixir library
W H AT ’ S S O M Y S T I C A L A B O U T I T ?
• High abstraction is powerful but can look intimidating to newcomers
• “Monads”
• Category theoretic basis
• Don’t need to know it
• Hask → Ex
WAT
M A K I N G T H E C A S E
W H Y A L L T H E E X T R A L I B R A R I E S ?
A L G E B R A I C C O D E
• “Algebra” here just means “a set of rules for manipulating related objects”
• You can make your own algebras
• Indeed you do without thinking about it
• For example, many DSLs and protocols
A L G E B R A I C C O D E
• High confidence
• Reusable abstractions (write once, run in many contexts)
• Declarative, pure/concurrent safe code
• More tools in your toolbox
• Convenience
• Well understood, principled, functional design patterns
• Lenses, free monad + interpreter, DSLs
• Unify similar concepts through abstraction
• +/2, ++/2, <>/2, Map.merge/2, MapSet.union/2 have a lot in common (semigroup)
D E S I G N
P R I N C I P L E S D R I V I N G
Compatibility with Elixir ecosystem
Consistency with mental models
Portability from other ecosystems
Pedagogy and approachability
– J O S E VA L I M
I would like to add a slightly different perspective to functional
programming in the Erlang VM: functional programming is not a goal
in the Erlang VM. It is a means to an end.

When designing the Erlang language and the Erlang VM, Joe, Mike
and Robert did not aim to implement a functional programming
language, they wanted a runtime where they could build distributed,
fault-tolerant applications. It just happened that the foundation for
writing such systems share many of the functional programming
principles. And it reflects in both Erlang and Elixir.
h t t p : / / b l o g . p l a t a f o r m a t e c . c o m . b r / 2 0 1 6 / 0 5 / b e y o n d - f u n c t i o n a l - p ro g r a m m i n g - w i t h - e l i x i r- a n d - e r l a n g /
– B R O O K LY N Z E L E N K A
How can I make this more like Haskell? (Bulb paradox)
B O O T S T R A P P I N G
Q U A R K • T Y P E C L A S S • A L G A E
B O O T S T R A P P I N G
Q U A R K T Y P E C L A S S
A L G A E
W I T C H C R A F T
Q U A R K
Q U A R K T Y P E C L A S S
A L G A E
W I T C H C R A F T
• Classic combinators
• id, flip, const, and so on
• Function composition
• Currying
• Very important for Witchcraft!
• Some constructs must be curried, 

and for convenience we do this dynamically
T Y P E C L A S S
Q U A R K T Y P E C L A S S
A L G A E
W I T C H C R A F T
• Principled type classes
• “Classes” and “methods” not the same as in OO
• Properties & methods
• Hierarchies
• Hiding side protocols from API
• Enum + Enumerable
A L G A E
Q U A R K T Y P E C L A S S
A L G A E
W I T C H C R A F T
• DSL for writing related structs
A L G A E
defdata
All of these fields
Roughly “and”
defsum
One of these structs
Roughly “or”
A L G A E
A L G A E . M AY B E
• Many uses, but can be “something or failure”
C O N S I S T E N C Y & E T H O S
K E E P I N G I T E L I X I R - Y
C O N S I S T E N C Y & E T H O S
• Introducing these concepts in other languages has been uneven
• Scalaz and Swiftz famously called “Haskell fan fiction”
• Some Scala looks like Java, some looks like Haskell, and hard to intermingle the two
• Elixir
• Borrowed the friendly community from Ruby
• Data flow and function application over classical expressions and composition
• Dynamically typed, or “type checked at runtime”
C O N S I S T E N C Y & E T H O S
The feeling that 

we’re trying to avoid
D I R E C T I O N A L I T Y & D ATA F L O W
• Let’s bootstrap people’s intuitions!
• Elixir prefers diagrammatic ordering
• Important to maintain consistency with rest of language!
• Pipes are generally awesome
• Want to maintain this awesomeness
• What if we just gave the pipe operator superpowers?
D ATA
x * 2
y + 1
|>
|>
2
4
5
• Witchcraft operators follow same
flow
• Data on flows through pointed
direction
• Just like pipes
• |> becomes ~> (curried map/2)
G I V I N G P I P E S S U P E R P O W E R S 💪
D ATA
x * 2
y + 1
~>
~>
[1,2,3]
[2,4,6]
[3,5,7]
D ATA
x * 2
y + 1
|>
|>
2
4
5
A S Y N C VA R I A N T S
Sequential Concurrent
• Operators follow same flow
• Data on flows through arrow direction
• |> (_)
• ~> <~
• ~>> <<~
• >>> <<<
G I V I N G P I P E S S U P E R P O W E R S 💪
M O R E P O W E R
map/2
ap/2
chain/2
apply/2
D E S I G N PAT T E R N S
T H E S E A R E F U N C T I O N A L & P R I N C I P L E D
W I T C H C R A F T 1 . 0 H I E R A R C H Y
S E M I G R O U P O I D
C AT E G O RY
A R R O W
S E M I G R O U P
M O N O I D
F O L D A B L E
T R AV E R S A B L E
F U N C T O R
A P P LY
A P P L I C AT I V E C H A I N
M O N A D
B I F U N C T O R
E X T E N D
C O M O N A D
F U N C T O R H I E R A R C H Y
F U N C T O R
A P P LY
A P P L I C AT I V E C H A I N
M O N A D
T R AV E R S A B L E B I F U N C T O R E X T E N D
C O M O N A D
• Provides map/2 (~>), but different from Enum
• Always returns the same type of data
• No more manual Enum.map(…)|> Enum.into(…)
F U N C T O R
• Provides convey/2 and ap/2
• Embellishes basic function application
• Specific embellishment changes per data type
A P P LY: T H I N K I N G I N S I D E T H E B O X
• Provide of/2
• Simple: lift values into a datatype
• Like List.wrap/1
A P P L I C AT I V E : P U T I N T O C O N T E X T
• Like Apply & Applicative, but with a special “linking” function
• Take raw value
• Do something to it
• Put the result into the original datatype
• Makes it easy to chain functions in a context
C H A I N : F U N C T I O N S T O A C T I O N S
P O W E R I N G U P G R A P H
F U N C T I O ND ATA R E S U LT|> ==
==~>>D ATA F U N C T I O N ( S ) R E S U LT ( S )
D ATA ~> F U N C T I O N == R E S U LT ( S )
==>>>D ATA L I N K I N G F U N R E S U LT ( S )
Application
Functor
Apply
Chain
C H A I N D O N O TAT I O N
• Macro to “linearize” chains
• Gives us back an operational feel
• Great DSLs (seen shortly)
M O N A D I C D O N O TAT I O N
• Need to specify the data type
• Just add return (specialized Applicative.of/2)
D O N O TAT I O N I M P L E M E N TAT I O N
S I M P L E D O - N O TAT I O N U S E S
L E T ’ S S E E S O M E C O D E !
W R I T E R M O N A D
Run 3x = num ^ 2 ^ 2 ^ 2
Need to specify more about

type in this case
Add one to tally
Square number
We know how many times

this has been run,
in a pure fashion
W R I T E R M O N A D
Log initial value
Add a “!” to input and log
Run 3 times
Log of transformations
Return the result
A R R O W S
P O W E R I N G U P D ATA F L O W
A R R O W S
I N P U T S P L I T
X + 1 S P L I T
X 2
U N S P L I T O U T P U T
U N S P L I T
I N S P E C T
X / 5
20
20
20
21
4
21
21
441
“21”
“44121”
4
“1”
A R R O W S
F U T U R E D I R E C T I O N S
• More ADTs, more type classes
• Pretty printing ADTs
• Automatic deriving
• Alternate minimal definitions (ex. right_fold or fold_map)
• GenArrow
T H A N K Y O U
• hex.pm/packages/witchcraft
• hex.pm/packages/quark
• hex.pm/packages/algae
• hex.pm/packages/type_class
• @expede
• brooklyn@robotoverlord.io

Weitere ähnliche Inhalte

Ähnlich wie Witchcraft

From Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dotsFrom Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dots
Ronald Ashri
 
From Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the DotsFrom Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the Dots
Ronald Ashri
 
SharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mindSharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mind
Chris Johnson
 

Ähnlich wie Witchcraft (20)

Data Modelling at Scale
Data Modelling at ScaleData Modelling at Scale
Data Modelling at Scale
 
Apache Spark: the next big thing? - StampedeCon 2014
Apache Spark: the next big thing? - StampedeCon 2014Apache Spark: the next big thing? - StampedeCon 2014
Apache Spark: the next big thing? - StampedeCon 2014
 
High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-End
 
Programming != Writing Code
Programming != Writing CodeProgramming != Writing Code
Programming != Writing Code
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
 
From Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dotsFrom Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dots
 
From Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the DotsFrom Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the Dots
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
MongoDB Europe 2016 - Using MongoDB to Build a Fast and Scalable Content Repo...
MongoDB Europe 2016 - Using MongoDB to Build a Fast and Scalable Content Repo...MongoDB Europe 2016 - Using MongoDB to Build a Fast and Scalable Content Repo...
MongoDB Europe 2016 - Using MongoDB to Build a Fast and Scalable Content Repo...
 
Bristol Uni - Use Cases of NoSQL
Bristol Uni - Use Cases of NoSQLBristol Uni - Use Cases of NoSQL
Bristol Uni - Use Cases of NoSQL
 
So You Want to Start Refactoring?
So You Want to Start Refactoring?So You Want to Start Refactoring?
So You Want to Start Refactoring?
 
Constructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languagesConstructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languages
 
The Swift Architect
The Swift ArchitectThe Swift Architect
The Swift Architect
 
Meteor WWNRW Intro
Meteor WWNRW IntroMeteor WWNRW Intro
Meteor WWNRW Intro
 
Choosing the Right Database
Choosing the Right DatabaseChoosing the Right Database
Choosing the Right Database
 
New Android Languages
New Android LanguagesNew Android Languages
New Android Languages
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
 
SharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mindSharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mind
 
Graph theory in Practise
Graph theory in PractiseGraph theory in Practise
Graph theory in Practise
 

Mehr von Brooklyn Zelenka (7)

Conf & Coffee: Survey Results
Conf & Coffee: Survey ResultsConf & Coffee: Survey Results
Conf & Coffee: Survey Results
 
Use the @types, Luke
Use the @types, LukeUse the @types, Luke
Use the @types, Luke
 
Witchcraft & Quark
Witchcraft & QuarkWitchcraft & Quark
Witchcraft & Quark
 
Gourmet Service Object
Gourmet Service ObjectGourmet Service Object
Gourmet Service Object
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for Rubyists
 
Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)
 
A (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingA (very brief) into to Functional Programming
A (very brief) into to Functional Programming
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Witchcraft

  • 1. W I T C H C R A F T M O N A D S F O R T H E W O R K I N G A L C H E M I S T
  • 2. W I T C H C R A F T M O N A D S F O R T H E W O R K I N G A L C H E M I S T L O T S O F S T U F F
  • 3. A B O U T T H I S TA L K • The Witchcraft suite: easier algebraic code for Elixir • Don’t need to know Haskell/Idris/PureScript/cat theory, but it helps • Throwing a lot at you (sorry) • Only covering a subset of what’s in these libraries • One takeaway:
  • 4. B R O O K LY N Z E L E N K A • @expede • Founding partner at Robot Overlord • Runs the Vancouver Functional Programming 
 and Vancouver Erlang/Elixir Meetups • Author of Witchcraft, TypeClass, Algae, Quark, Exceptional, and others • I have Witchcraft stickers (come see me afterwards)
  • 5. W H AT ’ S I N A N A M E ? witchcraft noun /ˈwɪtʃˌkrɑːft/ 1. the art or power of bringing magical or preternatural power to bear or the act or practice of attempting to do so 2. the influence of magic or sorcery 3. fascinating or bewitching influence or charm 4. an Elixir library
  • 6. W H AT ’ S S O M Y S T I C A L A B O U T I T ? • High abstraction is powerful but can look intimidating to newcomers • “Monads” • Category theoretic basis • Don’t need to know it • Hask → Ex WAT
  • 7. M A K I N G T H E C A S E W H Y A L L T H E E X T R A L I B R A R I E S ?
  • 8. A L G E B R A I C C O D E • “Algebra” here just means “a set of rules for manipulating related objects” • You can make your own algebras • Indeed you do without thinking about it • For example, many DSLs and protocols
  • 9. A L G E B R A I C C O D E • High confidence • Reusable abstractions (write once, run in many contexts) • Declarative, pure/concurrent safe code • More tools in your toolbox • Convenience • Well understood, principled, functional design patterns • Lenses, free monad + interpreter, DSLs • Unify similar concepts through abstraction • +/2, ++/2, <>/2, Map.merge/2, MapSet.union/2 have a lot in common (semigroup)
  • 10. D E S I G N P R I N C I P L E S D R I V I N G Compatibility with Elixir ecosystem Consistency with mental models Portability from other ecosystems Pedagogy and approachability
  • 11. – J O S E VA L I M I would like to add a slightly different perspective to functional programming in the Erlang VM: functional programming is not a goal in the Erlang VM. It is a means to an end.
 When designing the Erlang language and the Erlang VM, Joe, Mike and Robert did not aim to implement a functional programming language, they wanted a runtime where they could build distributed, fault-tolerant applications. It just happened that the foundation for writing such systems share many of the functional programming principles. And it reflects in both Erlang and Elixir. h t t p : / / b l o g . p l a t a f o r m a t e c . c o m . b r / 2 0 1 6 / 0 5 / b e y o n d - f u n c t i o n a l - p ro g r a m m i n g - w i t h - e l i x i r- a n d - e r l a n g /
  • 12. – B R O O K LY N Z E L E N K A How can I make this more like Haskell? (Bulb paradox)
  • 13. B O O T S T R A P P I N G Q U A R K • T Y P E C L A S S • A L G A E
  • 14. B O O T S T R A P P I N G Q U A R K T Y P E C L A S S A L G A E W I T C H C R A F T
  • 15. Q U A R K Q U A R K T Y P E C L A S S A L G A E W I T C H C R A F T • Classic combinators • id, flip, const, and so on • Function composition • Currying • Very important for Witchcraft! • Some constructs must be curried, 
 and for convenience we do this dynamically
  • 16. T Y P E C L A S S Q U A R K T Y P E C L A S S A L G A E W I T C H C R A F T • Principled type classes • “Classes” and “methods” not the same as in OO • Properties & methods • Hierarchies • Hiding side protocols from API • Enum + Enumerable
  • 17. A L G A E Q U A R K T Y P E C L A S S A L G A E W I T C H C R A F T • DSL for writing related structs
  • 18. A L G A E defdata All of these fields Roughly “and” defsum One of these structs Roughly “or”
  • 19. A L G A E
  • 20. A L G A E . M AY B E • Many uses, but can be “something or failure”
  • 21. C O N S I S T E N C Y & E T H O S K E E P I N G I T E L I X I R - Y
  • 22. C O N S I S T E N C Y & E T H O S • Introducing these concepts in other languages has been uneven • Scalaz and Swiftz famously called “Haskell fan fiction” • Some Scala looks like Java, some looks like Haskell, and hard to intermingle the two • Elixir • Borrowed the friendly community from Ruby • Data flow and function application over classical expressions and composition • Dynamically typed, or “type checked at runtime”
  • 23. C O N S I S T E N C Y & E T H O S The feeling that 
 we’re trying to avoid
  • 24. D I R E C T I O N A L I T Y & D ATA F L O W • Let’s bootstrap people’s intuitions! • Elixir prefers diagrammatic ordering • Important to maintain consistency with rest of language! • Pipes are generally awesome • Want to maintain this awesomeness • What if we just gave the pipe operator superpowers? D ATA x * 2 y + 1 |> |> 2 4 5
  • 25. • Witchcraft operators follow same flow • Data on flows through pointed direction • Just like pipes • |> becomes ~> (curried map/2) G I V I N G P I P E S S U P E R P O W E R S 💪 D ATA x * 2 y + 1 ~> ~> [1,2,3] [2,4,6] [3,5,7] D ATA x * 2 y + 1 |> |> 2 4 5
  • 26. A S Y N C VA R I A N T S Sequential Concurrent
  • 27. • Operators follow same flow • Data on flows through arrow direction • |> (_) • ~> <~ • ~>> <<~ • >>> <<< G I V I N G P I P E S S U P E R P O W E R S 💪 M O R E P O W E R map/2 ap/2 chain/2 apply/2
  • 28. D E S I G N PAT T E R N S T H E S E A R E F U N C T I O N A L & P R I N C I P L E D
  • 29. W I T C H C R A F T 1 . 0 H I E R A R C H Y S E M I G R O U P O I D C AT E G O RY A R R O W S E M I G R O U P M O N O I D F O L D A B L E T R AV E R S A B L E F U N C T O R A P P LY A P P L I C AT I V E C H A I N M O N A D B I F U N C T O R E X T E N D C O M O N A D
  • 30. F U N C T O R H I E R A R C H Y F U N C T O R A P P LY A P P L I C AT I V E C H A I N M O N A D T R AV E R S A B L E B I F U N C T O R E X T E N D C O M O N A D
  • 31. • Provides map/2 (~>), but different from Enum • Always returns the same type of data • No more manual Enum.map(…)|> Enum.into(…) F U N C T O R
  • 32. • Provides convey/2 and ap/2 • Embellishes basic function application • Specific embellishment changes per data type A P P LY: T H I N K I N G I N S I D E T H E B O X
  • 33. • Provide of/2 • Simple: lift values into a datatype • Like List.wrap/1 A P P L I C AT I V E : P U T I N T O C O N T E X T
  • 34. • Like Apply & Applicative, but with a special “linking” function • Take raw value • Do something to it • Put the result into the original datatype • Makes it easy to chain functions in a context C H A I N : F U N C T I O N S T O A C T I O N S
  • 35. P O W E R I N G U P G R A P H F U N C T I O ND ATA R E S U LT|> == ==~>>D ATA F U N C T I O N ( S ) R E S U LT ( S ) D ATA ~> F U N C T I O N == R E S U LT ( S ) ==>>>D ATA L I N K I N G F U N R E S U LT ( S ) Application Functor Apply Chain
  • 36. C H A I N D O N O TAT I O N • Macro to “linearize” chains • Gives us back an operational feel • Great DSLs (seen shortly)
  • 37. M O N A D I C D O N O TAT I O N • Need to specify the data type • Just add return (specialized Applicative.of/2)
  • 38. D O N O TAT I O N I M P L E M E N TAT I O N
  • 39. S I M P L E D O - N O TAT I O N U S E S L E T ’ S S E E S O M E C O D E !
  • 40. W R I T E R M O N A D Run 3x = num ^ 2 ^ 2 ^ 2 Need to specify more about
 type in this case Add one to tally Square number We know how many times
 this has been run, in a pure fashion
  • 41. W R I T E R M O N A D Log initial value Add a “!” to input and log Run 3 times Log of transformations Return the result
  • 42. A R R O W S P O W E R I N G U P D ATA F L O W
  • 43. A R R O W S I N P U T S P L I T X + 1 S P L I T X 2 U N S P L I T O U T P U T U N S P L I T I N S P E C T X / 5 20 20 20 21 4 21 21 441 “21” “44121” 4 “1”
  • 44. A R R O W S
  • 45. F U T U R E D I R E C T I O N S • More ADTs, more type classes • Pretty printing ADTs • Automatic deriving • Alternate minimal definitions (ex. right_fold or fold_map) • GenArrow
  • 46. T H A N K Y O U • hex.pm/packages/witchcraft • hex.pm/packages/quark • hex.pm/packages/algae • hex.pm/packages/type_class • @expede • brooklyn@robotoverlord.io