Skip to content

Instantly share code, notes, and snippets.

View adam-arold's full-sized avatar
💭
Exploring the n'th dimension.

Adam Arold adam-arold

💭
Exploring the n'th dimension.
View GitHub Profile
@adam-arold
adam-arold / KotlinFilterOperation.kt
Created September 11, 2017 16:38
KotlinFilterOperation
val reference = KotlinFilterOperation()::filterBy
@adam-arold
adam-arold / JavaUser.java
Created September 11, 2017 16:39
JavaUser
public class JavaUser {
// ...
public static Set<String> fetchCitiesOfUsers(
List<JavaUser> users) {
return users.stream()
.flatMap(user -> user.addresses.stream())
.map(JavaUser.Address::getCity)
.collect(Collectors.toSet());
@adam-arold
adam-arold / fetchCitiesOfUsers.kt
Created September 11, 2017 16:39
fetchCitiesOfUsers
fun fetchCitiesOfUsers(users: List<KotlinUser>) = users
.flatMap(KotlinUser::addresses)
.map(Address::city)
.toSet()
@adam-arold
adam-arold / KotlinInterop.java
Created September 11, 2017 16:40
KotlinInterop
public class KotlinInterop {
public void helloJava() {
System.out.println("Hello from Java!");
}
public void helloKotlin() {
JavaInterop.createInstance().helloKotlin();
}
}
@adam-arold
adam-arold / JavaInterop.kt
Created September 11, 2017 16:41
JavaInterop
class JavaInterop {
fun helloJava() {
KotlinInterop().helloJava()
}
fun helloKotlin() {
println("Hello from Kotlin!")
}
class Foo {
private val c: String
init {
bar()
c = ""
}
private fun bar() {
println(c.length)
}
}
val map = ConcurrentHashMap<String, String>()
map["foo"] = "bar"
val bar: String = map["foo"]!!
val queue: Queue<String> = LinkedList()
queue.peek().toInt()
/**
* Retrieves, but does not remove, the head of this queue,
* or returns {@code null} if this queue is empty.
*
* @return the head of this queue, or {@code null} if this queue is empty
*/
E peek();
val queue: Queue<String?> = LinkedList()
queue.peek()?.toInt()