Scala self-recursive types

One of the advantages of using a statically typed language is that you can use the type system to enforce some constraints. Scala provides self-recursive types, aka F-bounded polymorphic types that–along with self types–let you put powerful constraint to your type definitions. Self-recursive type definition Terminology apart, let me show you one of the use cases where this could be useful. Consider the following example which does not use a self-recursive type:

Scala DSL for currency-related operations

A simple internal DSL in Scala for money-related operations Source code: Scala DSL for money-related operations This Domain-Specific Language (DSL) lets you perform operations among different currencies, by transparently doing all internal conversions. The conversion map is injected implicitly by the client code. Usage Example Here’s a simple usage example: import import object Main { def main(args: Array[String]): Unit = { val conversion: Conversion = Map( (GBP, EUR) -> 1.

Try-Success-Failure API for Java 8

Try-Success-Failure API: Java implementation of the famous Scala counterpart Source code: Try-Success-Failure API for Java This API is a Java implementation of Scala Try API, originally implemented by the guys at Twitter and later added to the Scala Standard Library. The Try type represents a computation that may fail. If the computation is successful returns the value wrapped in a Try.Success otherwise returns the java.lang.Exception wrapped in a Try.Failure.