Functional Scala: Algebraic Datatypes – Enumerated Types

Welcome to another episode of Functional Scala!

This episode is the first part of at least two episodes we’re gonna take a deeper look at what’s called Algebraic datatypes and how you could build some of them on your own in Scala. An algebraic datatype reflects the idea, that a type is – loosely spoken – a set of certain (data) values. So in it’s very simplest form, an algebraic datatype can be defined by giving an enumeration of all the individual data values for a given type (of course you always also need to give the type an appropriate name). Read the rest of this entry »

Functional Scala: Polymorphic Functions ?!?

Welcome to another episode of Functional Scala!

If you’re coming from the object oriented world, chances are good that you’ve already heard something about a concept called Polymorphism. You may also know that there are different classes of Polymorphism out there: most of us are familiar with so called (Sub-)Type polymorphism and Parametric polymorphism (you may call it Generics).

Since functions take a central role within Functional Programming (i need to mention this, in case you’ve forgotten it), we want to take a closer look if Scala allows for so called polymorphic functions, which plays in the area of parametric polymorphism. If you’re now asking what the heck do we need polymorphic functions for (if anything), you’re coming to the right place! Read the rest of this entry »

Functional Scala: Turning Methods into Functions (or WTF is eta expansion?)

Welcome back to another episode of Functional Scala!

First of all, a happy new year to all of you – this year will bring a bunch of new episodes about ‘Functional Scala’ to you, so i hope we’ll grasp a better and better understanding over time on how Scala enables us to write functional code. Again, we’ve only scratched the surface so far – there are far more basic functional concepts (like curried functions, algebraic datatypes, pattern matching, …) to come, before we dig down into some more advanced topis like catamorphisms (sounds cool, eh? But trust me, the idea behind is really simple – you even saw already some examples of it using folds) or type classes and some of their instances (i.e. Functors, Applicatives and even – drum roll – those ubiquitous mentioned ‘warm fuzzy things’ , ehm i mean Monads). Read the rest of this entry »