bob
03/06/2017, 9:11 PMvoddan
04/01/2017, 1:53 PMKFunction1<@ParameterName(name = "ctx") RoutingContext, Unit>
? Is it better than (ctx: RoutingContext) -> Unit
?vinicius.rob.cunha
05/05/2017, 2:16 PMread.cutOn != meterCut && (meter.cutDate != null || readDate.after(meter.cutDate))
Daniel
05/08/2017, 11:09 PMsource.minBy { it.startX }?.startX ?: 0
Maybe a way to get the value of the property directly from the collection instead the object which it belongs to?cleiter
05/09/2017, 8:38 AMval (a, b) = if (true) Pair("a", "b") else Pair(null, null)
michaelsims
05/10/2017, 1:54 PMvar num
, no var buf
michaelsims
05/10/2017, 1:54 PMwhile (true) {
val num = fi.read(buf).takeIf { it > 0 } ?: break
fo.write(buf, 0, num)
}
pguardiola
05/28/2017, 8:12 AMString
doesn’t complaint don’t know why but it works ¯\_(ツ)_/¯
thanks @anstaendig 👍tipsy
06/03/2017, 12:45 PMdh44t
06/03/2017, 8:11 PMjlleitschuh
06/05/2017, 9:11 PMinterface IncomingJsonMessageHandler {
operator fun invoke(methodName: String, arg: String): String
}
Is this really the only good way to declare the constructor so that I can use it both for DI and as a lambda in tests is to do this goofyness:
class IncomingRPCHandler
@Inject constructor(
private val connectionProvider: ConnectionProvider,
private val incomingJsonMessageHandler: IncomingJsonMessageHandler) {
internal constructor(
connectionProvider: ConnectionProvider,
incomingJsonMessageHandler: (String, String) -> String) :
this(connectionProvider, object : IncomingJsonMessageHandler {
override fun invoke(methodName: String, arg: String): String = incomingJsonMessageHandler(methodName, arg)
})
x80486
06/18/2017, 2:37 AMimport org.jetbrains.kotlin.com.intellij.util.TimeoutUtil
val formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")
val regex = Regex("^V\\d+__.*\\.js\$")
File("src/main/resources/db/migration").walk()
.filterNot { it.isDirectory or it.name.matches(regex) }
.forEach {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC).format(formatter)
it.renameTo(File("${it.parent}${File.separatorChar}V${timestamp}__${it.name}"))
TimeoutUtil.sleep(100) // Wait for a moment to avoid prefix conflicts when renaming multiple files in a batch
}
trubesv
09/16/2017, 12:11 PMEugen Martynov
10/10/2017, 5:53 PMalchzh
11/20/2017, 2:26 PMmenegatti
11/21/2017, 3:13 PMShawn
11/23/2017, 7:42 PMjkbbwr
12/15/2017, 8:11 PM!!
is a code smell.
B) Why crush it down further.elect
12/15/2017, 10:13 PMsrcConnections.getOrPut(src, ::arrayListOf) += c
Dave Leeds
01/09/2018, 6:50 PMprivate enum class NestingCharacters(val open: String, val close: String) {
BRACE("{", "}"),
PAREN("(", ")"),
BRACKET("[", "]");
fun apply(char: String, stack: Stack<String>) {
when (char) {
open -> stack.push(char)
close -> {
val top = stack.peek()
if (stack.isStackEmpty()) throw SyntaxErrorTwoException(char)
if (top == open) stack.pop() else throw SyntaxErrorThreeException(top, char)
}
}
}
}
fun linter2(line: String): Boolean {
with(Stack<String>()) {
line.split("").forEach { char ->
NestingCharacters.values().forEach { it.apply(char, this) }
}
if (isNotEmpty()) throw SyntaxErrorOneException(peek())
}
return true
}
roberto.guerra
01/11/2018, 6:22 PMShawn
01/19/2018, 5:00 PMif (!existCell.isEmpty()) {
cell = when(existCell[existCell.size - 1]) {
1 -> 9
3 -> 7
7 -> 3
9 -> 1
else -> 0 // or some default value
}
}
rocketraman
01/22/2018, 2:56 PModay
01/23/2018, 8:13 AMAyden
01/23/2018, 3:25 PMif (
player1List.containsAll(listOf(1, 3, 7)) ||
player1List.containsAll(listOf(1, 3, 9)) ||
player1List.containsAll(listOf(1, 7, 9)) ||
player1List.containsAll(listOf(1, 3, 8))
) {
cell = 5
} else if (
player1List.containsAll(listOf(1, 3, 4))
) {
cell = 2
} else if (
player1List.containsAll(listOf(1, 5, 7))
) {
cell = 3
} else if (
player1List.containsAll(listOf(1, 3, 5)) ||
player1List.containsAll(listOf(1, 2, 4))
) {
cell = 7
} else if (player1List.containsAll(listOf(3, 5, 9))) {
cell = 1
}
dave08
01/29/2018, 3:20 AMJoe
02/02/2018, 12:53 PMlet
actually returns something.uhe
02/02/2018, 3:03 PMif else
is more readablemarcinmoskala
02/10/2018, 5:38 AMsubscriptions += repository.getQuests()
.applySchedulers()
.smartSubscribe(
onSuccess = view::showList and this::updateUpTrackingList,
onError = view::handleError,
onFinish = view::hideLoader
)
Which is, as you can guess, RxJava usage. On success I use both show list on view instance (this is in presenter) and I update tracking list:
private fun updateUpTrackingList(quests: List<Quest>) {
AppDatabase.addAppsToInstall(*quests.map { it.pkg }.toTypedArray())
}
and
is obviously commonly used function in my projects:
infix fun <T> ((T) -> Unit).and(f: (T) -> Unit): (T) -> Unit = { this(it); f(it) }
I had to add buffering, but I wanted to keep nice descriptive form of functions passing. So I made following function:
private var previousList: List<Quest>? = null
private fun ifChanged(onListChanged: (List<Quest>) -> Unit) = fun(list: List<Quest>) {
if(previousList != list) {
previousList = list
onListChanged(list)
}
}
And I use it this way:
subscriptions += repository.getQuests()
.applySchedulers()
.smartSubscribe(
onSuccess = ifChanged(view::showList and this::updateUpTrackingList),
onError = view::handleError,
onFinish = view::hideLoader
)
For me it looks great but I am not sure if it is not too complex for other people. What do you think? @mg6maciej? Functional programming passionates? Everyone?
PS. If I would have function delegate then I could even extract this buffering as a common patter (my proposition for this functionality is waiting on KEEP)elect
02/14/2018, 10:24 AMvar navEarliestChild = g.navWindow!!
while (navEarliestChild.parentWindow != null && navEarliestChild.parentWindow!!.flags has Wf.ChildMenu)
navEarliestChild = navEarliestChild.parentWindow!!
elect
02/14/2018, 10:24 AMvar navEarliestChild = g.navWindow!!
while (navEarliestChild.parentWindow != null && navEarliestChild.parentWindow!!.flags has Wf.ChildMenu)
navEarliestChild = navEarliestChild.parentWindow!!
Andreas Sinz
02/14/2018, 10:44 AMelect
02/14/2018, 11:31 AMAndreas Sinz
02/14/2018, 11:37 AMelect
02/14/2018, 3:39 PMMax Russek
02/14/2018, 10:06 PMgenerateSequence
might help https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/generate-sequence.html