Skip to content

Instantly share code, notes, and snippets.

View belyaev-mikhail's full-sized avatar

Mikhail Belyaev belyaev-mikhail

  • SPBSTU
  • Saint-Petersburg, Russia
View GitHub Profile
package ru.spbstu.util;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.Consumer;
<%
def k = number
def formattedList = { format, range -> range.collect{String.format(format, it)} }
def formatted = { format, range -> formattedList(format, range).join(", ") }
package ru.spbstu.util;
<%
def k = number
def formattedList = { format, range -> range.collect{String.format(format, it)} }
def formatted = { format, range -> formattedList(format, range).join(", ") }
%>
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Consumer;
package kotlinPlay
fun <S, T: S> Iterable<T>.reduceWithDefault(default: S, operation: (S, T) -> S): S =
if(this.any()) this.reduce(operation) else default
interface JsonElement {}
data class StringJsonElement(val v: String): JsonElement{}
data class DoubleJsonElement(val v: Double): JsonElement{}
data class ArrayJsonElement(val elements: Array<out JsonElement>): JsonElement{}
data class ObjectJsonElement(val v: Map<String, JsonElement>): JsonElement{}
import java.util.*
import kotlin.properties.Delegates
interface Location{
fun consume(ch: Char): Location
}
data class SimplestLocation(val position: Int): Location {
override fun consume(ch: Char) = SimplestLocation(position + 1)
}
package ru.spbstu
import java.lang.reflect.GenericArrayType
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.lang.reflect.WildcardType
import java.util.*
import java.util.stream.Stream
import kotlin.reflect.KCallable
import kotlin.reflect.KClass
#include <cstdint>
#include <vector>
#include <limits>
#include <cstring>
#include <iostream>
#include <string>
#include <type_traits>
#include <cstring>
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@kotlin.annotation.Target(AnnotationTarget.TYPE)
annotation class Whatever
fun main(args: Array<String>) {
val example = ({x: @Whatever Int ->})
}
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@kotlin.annotation.Target(AnnotationTarget.VALUE_PARAMETER)
annotation class Whatever
fun main(args: Array<String>) {
fun local(@Whatever x : Int) {}
println(::local.reflect()?.parameters?.first()?.annotations?.size) // prints 0
}
data class UncookedAnnotation(val name: String, val params: Map<String, Any?>)
val KType.uncookedAnnotations
get() = this.kotlinType.annotations.map { desc ->
UncookedAnnotation(
kotlin.reflect.jvm.internal.impl.renderer.DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(desc.type),
desc.allValueArguments.asSequence().map { (k, v) -> Pair("${k.name}", v.value) }.toMap()
)
}
package org.jetbrains.research.kotoed.util
import kotlinx.coroutines.experimental.Unconfined
import kotlinx.coroutines.experimental.launch
import org.junit.Test
import kotlin.coroutines.experimental.suspendCoroutine
import kotlin.reflect.KProperty
class Playground {