I'm running into deeply nested ?.let calls very of...
# getting-started
b
I'm running into deeply nested ?.let calls very often, is there something like Haskell's do notation that does not require nesting but brings things into scope?
arrow 1
1
y
Try out Arrow's
nullable
blocks
s
maybe chain the null safe operator
?.
more often!?
Copy code
bob?.department?.head?.name?.let { name: String -> ... }
https://kotlinlang.org/docs/null-safety.html#safe-calls also check your domain models, maybe they contain more nullable properties if they need to.
c
Arrow's nullable block is what you're searching for:
Copy code
val result = foo
  ?.let { a -> b(a) }
  ?.let { b -> c(b) }
  ?.let { c -> d(c) }
becomes
Copy code
val result = nullable {
    val b = b(foo).bind()
    val c = c(b).bind()
    d(c)
}
b
thanks