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
From cf90b931886b5414bd7db6d14eb5f7aa9a3b7329 Mon Sep 17 00:00:00 2001 | |
From: Sergio Gutierrez <[email protected]> | |
Date: Wed, 3 Oct 2018 10:27:23 +0200 | |
Subject: [PATCH] Fix facebook version in test | |
--- | |
core/src/test/scala/com/karumi/shot/domain/ConfigSpec.scala | 2 +- | |
shot-consumer/build.gradle | 2 +- | |
2 files changed, 2 insertions(+), 2 deletions(-) |
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
// Return a map of the customers living in each city | |
fun Shop.groupCustomersByCity(): Map<City, List<Customer>> = | |
customers.groupBy { it.city } |
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
// Return the set of products that were ordered by every customer | |
fun Shop.getSetOfProductsOrderedByEveryCustomer(): Set<Product> { | |
val allProducts = customers.flatMap { it.orders.flatMap { it.products } }.toSet() | |
return customers.fold(allProducts) { acc, customer -> | |
acc.intersect(customer.orders.flatMap { it.products } ) | |
}.toSet() | |
} |
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
// Return all products this customer has ordered | |
val Customer.orderedProducts: Set<Product> get() { | |
return orders.flatMap { it.products }.toSet() | |
} | |
// Return all products that were ordered by at least one customer | |
val Shop.allOrderedProducts: Set<Product> get() { | |
return customers.flatMap { it.orderedProducts }.toSet() | |
} |
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
// Return the set of cities the customers are from | |
fun Shop.getCitiesCustomersAreFrom(): Set<City> = customers.map { it.city }.toSet() | |
// Return a list of the customers who live in the given city | |
fun Shop.getCustomersFrom(city: City): List<Customer> = customers.filter { it.city == city } |
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
sealed class Vinyl { | |
object Skull : Vinyl() | |
data class Angels(val numberOfAngels: Int) : Vinyl() | |
data class Flowers(val numberOfFlowers: Int) : Vinyl() | |
data class Guns(val label: String) : Vinyl() | |
object Boots : Vinyl() | |
} | |
typealias Flag = Color |
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
interface Sellable { | |
var priceInEuros: Int | |
var priceInDollars: Int | |
get() = (priceInEuros * 1.06).toInt() | |
set(value) { | |
priceInEuros = (value / 1.06).toInt() | |
} | |
} | |
interface Describable { |
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
abstract class Product( | |
val id: String | |
) { | |
abstract val name: String | |
abstract var priceInEuros: Int | |
var priceInDollars: Int | |
get() = (priceInEuros * 1.06).toInt() | |
set(value) { | |
priceInEuros = (value / 1.06).toInt() | |
} |
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 sum1(a: Int?, b: Int?): Int { | |
b ?: return 0 | |
return if (a != null) { | |
a + b | |
} else { | |
5 + b | |
} | |
} |
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
tailrec fun fizzbuzz(vararg args: Int) { | |
if (args.isEmpty()) return | |
val arg = args[0] | |
when { | |
arg % 15 == 0 -> print("FizzBuzz") | |
arg % 3 == 0 -> print("Fizz") | |
arg % 5 == 0 -> print("Buzz") | |
} |
NewerOlder