kirillrakhman
10/06/2016, 11:22 AMnotEmptyAndAll
, but yeahkirillrakhman
10/06/2016, 11:23 AManyAll
wouldn't be clear at alldimsuz
10/06/2016, 11:27 AMkirillrakhman
10/06/2016, 1:13 PMClosedRange.component1()
and component2()
?ilya.gorbunov
10/06/2016, 1:20 PMIntRange
is a ClosedRange
though not a list, so these components won't clash if we introduce them for ClosedRange
. However they may confuse user as now two very similar constructions will mean kinda different things.kirillrakhman
10/06/2016, 1:20 PMkirillrakhman
10/06/2016, 1:20 PMkirillrakhman
10/06/2016, 1:21 PMkirillrakhman
10/06/2016, 1:22 PMdebug
10/06/2016, 3:54 PMfun Boolean.whenTrue(block: () -> Unit): Boolean {
if (this) block()
return this
}
fun Boolean.whenFalse(block: () -> Unit): Boolean {
if (!this) block()
return this
}
fun main(args: Array<String>) {
true.whenTrue { println("That's true") }
.whenFalse{ println("That isn't true") }
}
@orangy This would work, I thought this would be cool if it were in stdlib, but again, I suppose it's too minor to be adding things like this there.roman.belov
10/06/2016, 4:51 PMorangy
val value = condition.whenTrue {1}.whenElse{0}
debug
10/06/2016, 5:23 PMpabl0rg
10/14/2016, 6:47 PMstepango
10/17/2016, 10:10 AM@get:Suppress("") val foo:String = "Hello World" @Suppress("") get
works fine, but @get:Suppress("") @get:Suppress("") val foo:String = "Hello World"
- error This annotation is not repeatable
Is is a bug of a feature?yole
10/17/2016, 10:13 AMstepango
10/17/2016, 10:19 AMstepango
10/19/2016, 4:03 AMfun '_'() = 3; _()
works fine, but fun '$'() = 3; $()
is not valid, is it expected behaviour? for fun _() = 3
i receive an error Names _, __, ... reserved
does it mean i shoundn't be able to call methods with names like __
?orangy
denis.zharkov
10/19/2016, 6:03 PMfun '$'() = 3; $()
looks like an issue, but I'm not sure. Please file a report https://youtrack.jetbrains.com/issues
Note that if you add a new line after ;
everything works
2. You always can declare it like fun '_'() = 3
and call it with _ name (again from the next line)h0tk3y
10/19/2016, 8:56 PMComparator<T>
to Comparator<in Iterable<T>>
conversion that will make a lexicographical comparator? Example implementation: https://github.com/h0tk3y/kotlin-fun/blob/master/src/main/kotlin/com/github/h0tk3y/kotlinFun/LexComparator.kt
This comparator might not be consistent with equals
, but Java comparator contract allows this.stepango
10/20/2016, 2:29 AMorangy
ilya.gorbunov
10/20/2016, 1:38 PMComparator<Sequence<T>>
or Comparator<Array<T>>
?
- from my experience of implementing comparator transformations like Comparator<T> -> Comparator<T?>
, extension functions don't fit quite well for that task. Top-level function might be better here. Have you tried to use such function in a fluent scenario? Imagine you have list, which elements are List<T>, and you want to sort its elements, comparing them lexicographically. How would you create comparator in this case?h0tk3y
10/20/2016, 2:19 PMsortedWith(comparator)
is suitable here:
listOf(listOf("a"), listOf("b"), listOf("ab")).sortedWith(naturalOrder<String>().lexicographically())
vs
listOf(listOf("a"), listOf("b"), listOf("ab")).sortedWith(lexicographical(naturalOrder()))
The difference is that type inference fails in case of extension function, requiring explicit type argument. Any other possible issues?h0tk3y
10/20/2016, 2:34 PMwill it be possible to provide the same API to buildSeems like there can only be separate functions fororComparator<Sequence<T>>
?Comparator<Array<T>>
Array
and Sequence
, because there's no such R
that Comparator<in R<T>>
matches them all.ilya.gorbunov
10/20/2016, 6:48 PMSeems like there can only be separate functionsYes, and these functions have to be named differently.
ilya.gorbunov
10/20/2016, 6:53 PMThe difference is that type inference fails in case of extension functionThat's what I've meant, but not only. Type inference issues might be fixed in 1.1, but nevertheless when you build comparator fluently, for example in such an expression:
listOfLists.sortedWith( compareBy { <cursor> } }
you will have the type of it
in compareBy
to be List<T>
, and to change it to T
, you'll have to add the extension call first, than return back to lambda body. Thus it hurts fluency.h0tk3y
10/20/2016, 8:07 PMh0tk3y
10/20/2016, 8:08 PM