Created
December 18, 2010 14:34
-
-
Save debasishg/746552 to your computer and use it in GitHub Desktop.
This file contains 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
// Reader monad | |
val lifecycle = for { | |
taxFeeIds <- forTrade // get the tax/fee ids for a trade | |
taxFeeValues <- taxFeeCalculate // calculate tax fee values | |
netAmount <- enrichTradeWith // enrich trade with net amount | |
} | |
yield((taxFeeIds ∘ taxFeeValues) ∘ netAmount) | |
// sample usage | |
val t1 = Map("account" -> "a-123", "instrument" -> "google", "refNo" -> "r-123", "market" -> "HongKong", "unitPrice" -> "12.25", "quantity" -> "200") | |
val t2 = Map("account" -> "b-123", "instrument" -> "ibm", "refNo" -> "r-234", "market" -> "Singapore", "unitPrice" -> "15.25", "quantity" -> "400") | |
describe("trades") { | |
it("should create and operate on multiple trades") { | |
import Trades._ | |
val trd1 = makeTrade(t1) | |
val trd2 = makeTrade(t2) | |
(trd1 ∘ lifecycle) should equal(Some(Some(3307.5000))) | |
(List(trd1, trd2) ∘∘ lifecycle) should equal (List(Some(Some(3307.5000)), Some(Some(8845.0000)))) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment