Dico
05/08/2019, 8:48 PMBala Subrahmanyam
05/09/2019, 7:47 AMIgbani Izuchukwu
05/10/2019, 3:15 AMkrtko
05/11/2019, 8:17 PMhhariri
karelpeeters
05/12/2019, 8:39 AMfun <T> box(value: T) = value
karelpeeters
05/12/2019, 8:45 AMjava.lang.Integer(6)
works.santiago
05/12/2019, 9:03 AMsantiago
05/12/2019, 9:13 AMnikospamp
05/12/2019, 8:18 PMPep Mendez
05/13/2019, 8:29 AMdavid-wg2
05/13/2019, 2:38 PMGuru
05/14/2019, 5:58 AMGuru
05/14/2019, 5:59 AMiex
05/14/2019, 11:38 PMnull
, than:
fun Foo.foo(): MyObj? {
val var1 = var1 ?: return null
val var2 = var2 ?: return null
return MyObj (var1, var2)
}
iex
05/14/2019, 11:39 PMreturn null
directly in the initialization of MyObj
🤔iex
05/15/2019, 3:18 PMval
of another class in init
🤔 I thought this would be impossiblenickk
05/15/2019, 4:10 PMclass Action(val field1: String, val field2: String, var closure: () -> Unit = {} ) { }
val myAction = Action("value1", "value2")
myAction.closure = {
callAnotherFunction(myAction)
}
collection.add(myAction)
Is there a way to avoid defining the temp variable and do it all at once?karelpeeters
05/15/2019, 4:26 PMval closure
should probably be a function instead, used as in myAction::closure
, but I'm trying to mimic your code as close as possible here.Hullaballoonatic
05/16/2019, 5:06 AMkarelpeeters
05/16/2019, 5:08 AMiex
05/16/2019, 6:30 PMsealed class Result<out T, out E> {
data class Ok<out T>(val value: T) : Result<T, Nothing>()
data class Err<out E>(val error: E) : Result<Nothing, E>()
fun <V> map(f: (T) -> V): Result<V, E> = when (this) {
is Ok -> Ok(f(value))
is Err -> this
}
fun <F> mapError(f: (E) -> F): Result<T, F> = when (this) {
is Ok -> this
is Err -> Err(f(error))
}
fun <V> flatMap(f: (T) -> Result<V, E>): Result<V, E> = when (this) { // <-- declared as "out" but it occurs in "in"
is Ok -> f(value)
is Err -> this
}
}
iex
05/16/2019, 6:30 PMout
from E
I get other errorsiex
05/16/2019, 6:32 PMiex
05/16/2019, 6:32 PMsealed class Result<out T, E> {
data class Ok<out T, E>(val value: T) : Result<T, E>()
data class Err<out T, E>(val error: E) : Result<T, E>()
fun <V> map(f: (T) -> V): Result<V, E> = when (this) {
is Ok -> Ok(f(value))
is Err -> Err(error)
}
fun <F> mapError(f: (E) -> F): Result<T, F> = when (this) {
is Ok -> Ok(value)
is Err -> Err(f(error))
}
fun <V> flatMap(f: (T) -> Result<V, E>): Result<V, E> = when (this) {
is Ok -> f(value)
is Err -> Err(error)
}
}
streetsofboston
05/16/2019, 6:46 PMsealed class Result<out T, out E> {
data class Ok<out T>(val value: T) : Result<T, Nothing>()
data class Err<out E>(val error: E) : Result<Nothing, E>()
}
fun <T,V,E> Result<T,E>.map(f: (T) -> V): Result<V, E> = when (this) {
is Result.Ok -> Result.Ok(f(value))
is Result.Err -> this
}
fun <T,E,F> Result<T,E>.mapError(f: (E) -> F): Result<T, F> = when (this) {
is Result.Ok -> this
is Result.Err -> Result.Err(f(error))
}
fun <T,V,E> Result<T,E>.flatMap(f: (T) -> Result<V, E>): Result<V, E> = when (this) {
is Result.Ok -> f(value)
is Result.Err -> this
}
Robert
05/16/2019, 7:56 PMInt
, but does not implement it on thru equals
(except for Native)? At least, not thru ==
comparison operatorFlorian
05/18/2019, 11:38 AMFlorian
05/18/2019, 12:29 PM