Scala - kanuku/misc GitHub Wiki
Scala blogs
apply
isDefinedAt
Partial Functions have a flaw, they don't
folds and maps, right and left
Collections Methods
map
flatMap
filter
foldLeft
foldRight
Scala test
Testing with Futures Examples
OPTIONS TRY AND EITHER
############################ OPTION ############################
Option basically means that a value can be absent and is mostly used as a
wrapper around the returning type of a method.
For example when looking up a value in a database the result could be empty.
In this case you should avoid returning null here or throwing an NotFound exception.
In Scala you will typically use the Option[T] type to return Some(value) when the
value is found and None when the value is absent or an Error occured which
the client shouldn't know about.
############################ EITHER ############################
A special type of error that can occur is the absence of some value.
For example when looking up a value in a database or a List you can
use the find method. When implementing this in Java the common solution
(at least until Java 7) would be to return null when a value cannot be
found or to throw some version of the NotFound exception. In Scala you
will typically use the Option[T] type, returning Some(value) when the
value is found and None when the value is absent or an Error occured which
the client doesn't need to know of.
Category Theory
The category theory is an algebraic structure that is applied in programming languages to describe entities and their relations. When expressed in programming languages, this theory describes certain rules and or guarantees related to:
- The association between types and subtypes
- The convertion of one type to another, i.e: conversion of a subtype to its supertype
- How to compose those relations between types or conversion from one type to another
Why is this necessary in programming languages?
Yes, unfortunately it is. Thanks to this this and other complex theories you are able to
####### Functors
Covariant
Arrays in Java are covariant because