Skip to content

Instantly share code, notes, and snippets.

View Serchinastico's full-sized avatar
👋

Sergio Gutiérrez Serchinastico

👋
View GitHub Profile
@Serchinastico
Serchinastico / filtermap.kt
Created September 17, 2018 15:49
filter;map koan
// 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 }
@Serchinastico
Serchinastico / flatmap.kt
Created September 17, 2018 16:00
flatmap koan
// 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()
}
@Serchinastico
Serchinastico / fold.kt
Created September 17, 2018 16:27
fold koan
// 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()
}
@Serchinastico
Serchinastico / groupby.kt
Created September 17, 2018 16:39
groupby koan
// Return a map of the customers living in each city
fun Shop.groupCustomersByCity(): Map<City, List<Customer>> =
customers.groupBy { it.city }
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(-)