Demystifying functional constructs: options, eithers, semigroups and monads
Functional programming often feels like black magic, but rest assured - it is not.
In fact, it is quite simple to grasp its constructs and the best way to do it is to implement them yourselves.
Depending on the time allocated, we will:
- Cover the basic ideas of functional programming.
- Implement our own Option type to deal with 'there is a result/there is no result' case.
- Implement our own Either type to deal with 'there is either A or B result' case.
- Implement a semigroup to demonstrate typeclass concept and the power of implicits in Scala by doing a arbitrary nested map (dictionary) merge using semigroups.
- Implement our own monad type and use it.
Language of the demo will be Scala, but these constructs can be implemented in almost any language.
a laptop, a programming language, a code editor.
Suggestions: https://www.scala-sbt.org/, https://www.jetbrains.com/idea/ (or other code editor supporting SBT).
I would recommend to initialize a simple Scala project, using instructions found at https://docs.scala-lang.org/getting-started-sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html