question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling call chains starting with a lambda call

See original GitHub issue

We need to make a decision on to handle something such as this:

with(Foo()) {
  doFooStuff()
  doMoreFooStuff()
}.also {
  println("Wow")
  println("Amaze")
}

Generally in call chains, we break before a dot, and in the case of a chain with lambdas code looks like this:

fooFoo
    .callMethod {
      doFooStuff()
      doMoreFooStuff()
    }
    .also {
      println("Wow")
      println("Amaze")
    }

There is an example a . which is a when expression:

when (f) {
  ...
}.exhaustive

A few options we have:

Option 1: dot right after }.

with(Foo()) {
  doFooStuff()
  doMoreFooStuff()
}.also {
  println("Wow")
  println("Amaze")
}

Problem: The chain keeps looking different than other types of chains

Option 2

Extra indentation to make it look like if we had a chained call

with(Foo()) {
      doFooStuff()
      doMoreFooStuff()
    }
    .also {
      println("Wow")
      println("Amaze")
    }

Problem, might be weird to have the extra indentation

Option 3

Floating dot

with(Foo()) {
  doFooStuff()
  doMoreFooStuff()
}
    .also {
      println("Wow")
      println("Amaze")
    }

What option should we pursue? I have code doing option 2.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
cgrushkocommented, Jan 16, 2021

@JavierSegoviaCordoba - GitHub Discussions enabled

1reaction
hick209commented, May 7, 2020

I prefer option 1 for the ones you presented.

But also, if it’s formatted differently, I’d go with option 3.

For example:

list.asSequence()
    .map { i ->
      i * 2
    }
    .also {
      println(it)
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chaining Together Lambdas: Exploring All the Different Ways ...
This post will walk through a few different methods to chain Lambdas together. ... Let's say you just want to call one Lambda...
Read more >
Asynchronous invocation - AWS Lambda
When you invoke a Lambda function asynchronously, Lambda places the request in a queue and returns a success response without additional information.
Read more >
Chaining Lambda Functions using the Serverless Framework
In this article I want to show how to chain AWS Lambda Functions which basically means calling a Lambda Function from another Lambda...
Read more >
AWS Lambda chaining best practice - Stack Overflow
Lambda A should call lambda B and if no results, it will call lambda C, and then return whatever the results are to...
Read more >
How to periodically call a Lambda function
Timing events. Serverless architectures are event-driven, things start processing when there is something that triggers them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found