This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Monoid[A] { | |
def identity: A | |
def mplus(a1: A, a2: A): A | |
} | |
object Monoid { | |
implicit val IntMonoid = new Monoid[Int] { | |
def identity = 0 | |
def mplus(a1: Int, a2: Int) = a1 + a2 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Positions { | |
trait Investment | |
trait Position { | |
def investment: Investment | |
def tradingPnL: Option[Double] | |
def inventoryPnL: Option[Double] | |
final def totalPnL = inventoryPnL → tradingPnL | |
} | |
import Monoid._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TradingDays extends App { | |
import scalaz._ | |
import Scalaz._ | |
case class Trade(sym: String, trader: String, qty: Int) | |
case class TradingDay(symbols: Map[String, SymDay] = Map.empty) | |
object TradingDay { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is how we create an inclusive/exclusive range of Ints: | |
val ie = 0 until 500 | |
//1. Fill in the missing item to create a range of Ints from 1 to 100 inclusive | |
val ints = 1 ??? 100 | |
//2. Find the sum of the integers in this range |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The declaration of a value in scala looks like this: | |
val x = 1 | |
// ^ ^ ^ | |
// ^ ^ the value we wish to assign our new value to | |
// ^ identifier (ie name of value) | |
// type of value (val or var) | |
// Each identifier in scala has an associated type (or, more accurately, it has many types ranging from the least to the most specific) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In scala a def (called a "method") is defined as follows: | |
def foo(arg: String): Int = expr | |
// ^ ^ ^^ ^ ^ ^ | |
// ^ ^ ^^ ^ ^ an expression, whose type must match the declared return type, if specified | |
// ^ ^ ^^ ^ ^ | |
// ^ ^ ^^ ^ the declared return type (optional). | |
// ^ ^ ^^ ^ | |
// ^ ^ ^^ the type of each argument must be declared | |
// ^ ^ ^^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._;import Scalaz._; import concurrent._ | |
/* Imagine you have some expensive calculations you wish to make: */ | |
trait RawApi { | |
def expensiveInt: Int = Int.MaxValue | |
def expensiveString: String = "expensive" | |
} | |
/* You wish to write a program using this API */ | |
case class Result(i: Int, s: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<scheme name="OxbowSolarizedDark2" version="124" parent_scheme="Default"> | |
<option name="LINE_SPACING" value="1.2" /> | |
<option name="EDITOR_FONT_SIZE" value="13" /> | |
<option name="EDITOR_FONT_NAME" value="Consolas" /> | |
<colors> | |
<option name="ADDED_LINES_COLOR" value="" /> | |
<option name="ANNOTATIONS_COLOR" value="2b36" /> | |
<option name="ANNOTATIONS_MERGED_COLOR" value="" /> | |
<option name="CARET_COLOR" value="dc322f" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////////////////////////////////////////////// | |
// You are supplied with the following interfaces/implementations | |
/////////////////////////////////////////////////////////////////////// | |
/** Interface representing the performing of a computation at some specific key */ | |
public interface Computation<K, V> { | |
K key(); | |
V compute(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger | |
/** | |
* Clients can use this class instead, which means they only need fill in the | |
* V compute(K) method | |
*/ | |
abstract class ConcCache2<K, V> { | |
private final ConcCache<K, V> cache = new ConcCache<>(); | |