Hey, :arrow: gurus. Where can I find an applicatio...
# arrow
r
Hey, arrow gurus. Where can I find an application using the Raise DSL without context receivers?
g
Unfortunately the samples made by the team were before the declaration of the context receivers cautionary
I'm also looking for such an application
r
Ok, the problem is calling methods that can raise an error. For example, let’s look at the following code:
Copy code
interface CreatePortfolioUseCase {
    suspend fun Raise<DomainError>.createPortfolio(model: CreatePortfolio): PortfolioId
}
fun createPortfolioUseCase(): CreatePortfolioUseCase =
    object : CreatePortfolioUseCase {
        override suspend fun Raise<DomainError>.createPortfolio(model: CreatePortfolio): PortfolioId = 
            PortfolioId("1")
    }

private val underTest = createPortfolioUseCase()

@Test
internal fun `given a userId and an initial amount, when executed, then it create the portfolio`() =
    runTest {
        val actualResult: Either<DomainError, PortfolioId> =
            with(underTest) {
                either {
                     createPortfolio(CreatePortfolio(UserId("bob"), Money(1000.0)))
                }
            }
        assertThat(actualResult.getOrNull()).isEqualTo(PortfolioId("1"))
    }
The problem is that the class containing the method should be used as a context through the
with
function. My doubt is if there is a better way 🤷‍♂️
thank you color 1
c
that’s (unfortunately) the way - you use the extension receiver for the Raise DSL and need to bring the dispatch receiver into scope via
with
. Just finished converting an app from context receivers to this (as context receivers are a dead-end), its not as elegant as context receivers (or context parameters, when they arrive) but not too bad.
gratitude thank you 1
j
as context receivers are a dead-end
@Chris Lee why?
j
I didn't realise, thanks! I was just about to refactor a personal project to try how it'd look like with context receivers. I was tempted by the possibility of multiple
Raise<>
contexts. Having multiple Raise<>s wouldn't require a single error hierarchy so would work kinda like unions. I guess I'm not doing that anymore 😅
p
context-receivers
may be on their way out, but context-parameters are on their way in. There have been comments that there will be no gap between support for one and support for the other, but also that there is very likely to be no compiler version that supports both.
👍 2
thank you color 1