https://kotlinlang.org logo
Title
r

reik.schatz

05/09/2019, 10:04 AM
does kotlin have syntactic sugar for nullable types like the for-comprehension / yield thing in Scala? i.e. I have n-nullable variables and I want to yield only if they are all not null (return null otherwise)
the only thing I can come up with are nested
?.let
statements
val out: Foo? = map["key1"]?.let { one ->
	map["key2"]?.let { two ->
		Foo(one, two)
	}
}
scala pseudo syntax
val foo = for {
	one <- map["key1"]
	two <- map["key2"]
} yield Foo(one, two)
r

robstoll

05/09/2019, 10:10 AM
kotlin does not have for-comprehension. in this sense the nested
let
are similar to the nested
flatMap
which the for comprehension hides
r

reik.schatz

05/09/2019, 10:13 AM
ok thanks
k

kartoffelsup

05/09/2019, 11:18 AM
You can check out #arrow which has comprehensions based on coroutines
r

reik.schatz

05/09/2019, 11:47 AM
will check it out, thanks
s

streetsofboston

05/09/2019, 12:08 PM
Those ,on Arrow, are called
fx
(they exist for a bunch of monadic types, eg Option, Either, IO, etc)