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
<dependency> | |
<groupId>org.funktionale</groupId> | |
<artifactId>funktionale-composition</artifactId> | |
<version>1.1</version> | |
</dependency> |
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
<repository> | |
<id>central</id> | |
<name>bintray</name> | |
<url>http://jcenter.bintray.com</url> | |
</repository> |
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
data class Item(val name: String, val price: Double, val discount: Double, val quantity: Double) | |
object ItemDao { | |
fun findItemsForInvoice(invoiceId: Int): List<Item> { | |
return listOf( | |
Item("Item A", 10.0, 0.0, 1.0), | |
Item("Item B", 100.0, 0.0, 1.0), | |
Item("Item C", 50.0, 10.0, 3.0), | |
Item("Item D", 45.0, 0.0, 1.5), | |
Item("Item E", 8.5, 5.0, 20.0), |
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
val items = ItemDao.findItemsForInvoice(1) | |
val total = items | |
.map { (_, itemPrice, discount, quantity) -> itemPrice * quantity to discount } | |
.map { (price, discount) -> price to discount / 100.0 } | |
.map { (price, discPercentage) -> price - (price * discPercentage) } | |
.sum() |
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
val extract: (Item) -> Pair<Double, Double> = { (_, itemPrice, discount, quantity) -> itemPrice * quantity to discount } | |
val discount: (Pair<Double, Double>) -> Pair<Double, Double> = { (price, discount) -> price to discount / 100.0 } | |
val price: (Pair<Double, Double>) -> Double = { (price, discPercentage) -> price - (price * discPercentage) } |
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
val total = items | |
.map(extract) | |
.map(discount) | |
.map(price) | |
.sum() |
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
val total = items | |
.map(extract andThen discount andThen price) | |
.sum() |
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
fun underline(it: String) = "_${it}_" | |
fun background(it: String) = "\u001B[41m$it\u001B[0m" |
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
println((::underline forwardCompose ::background)("Hello")) | |
println((::underline compose ::background)("Hello")) |
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
import rx.Observable | |
import rx.Subscription | |
import rx.util.functions.Action1 | |
/** | |
* Created by IntelliJ IDEA. | |
* @author Mario Arias | |
* Date: 9/05/13 | |
* Time: 21:11 | |
*/ |