stefano.maffullo
08/17/2017, 12:26 PMstefano.maffullo
08/17/2017, 12:27 PMmenegatti
08/17/2017, 12:28 PMsumBy { it.faceValue }
menegatti
08/17/2017, 12:29 PMsumOrThrow
part of the stdlib?stefano.maffullo
08/17/2017, 12:29 PMstefano.maffullo
08/17/2017, 12:29 PMstefano.maffullo
08/17/2017, 12:30 PMstefano.maffullo
08/17/2017, 12:30 PMmenegatti
08/17/2017, 12:30 PMmenegatti
08/17/2017, 12:31 PMfaceValue
is and what is the expected result of summing two instances?alex.hart
08/17/2017, 12:33 PMsealed class DString {
class Empty internal constructor() : DString()
class NonEmpty internal constructor(val s: String) : DString()
companion object {
fun create(s: String?) = if (s.isNullOrEmpty()) Empty() else NonEmpty(s!!)
}
}
“protected” and “private” don’t work.alex.hart
08/17/2017, 12:38 PMdata class Note(title: DString.NonEmpty, body: DString.NonEmpty)
Sort of building data validation into the type system… a poor man’s dependent types I guesskarelpeeters
08/17/2017, 12:43 PMprotected
work?alex.hart
08/17/2017, 12:58 PMProtected gives a compilation error▾
alex.hart
08/17/2017, 1:00 PMalex.hart
08/17/2017, 1:04 PMsealed class DString {
class Empty private constructor() : DString() {
companion object {
val empty = Empty()
}
}
class NonEmpty private constructor(val s: String) : DString() {
companion object {
@Deprecated("Use [DString.create]")
fun create(s: String) = if (s.isNotEmpty()) NonEmpty(s) else Empty.empty
}
}
companion object {
@Suppress("DEPRECATION")
fun create(s: String?) = s?.let { NonEmpty.create(it) } ?: Empty.empty
}
}
alex.hart
08/17/2017, 1:05 PMalex.hart
08/17/2017, 1:11 PMkarelpeeters
08/17/2017, 1:16 PMkevinmost
08/17/2017, 1:16 PMkarelpeeters
08/17/2017, 1:18 PMalex.hart
08/17/2017, 1:18 PMalex.hart
08/17/2017, 1:19 PMkevinmost
08/17/2017, 1:19 PMkevinmost
08/17/2017, 1:19 PManupam67
08/17/2017, 1:48 PMevanchooly
08/17/2017, 1:48 PManupam67
08/17/2017, 1:48 PMdelater
08/17/2017, 1:49 PM