Omg, we needed context receivers like 2 years ago....
# arrow-contributors
s
Omg, we needed context receivers like 2 years ago.. (After some discussions in Scala I tried something..)
Copy code
context(Raise<E>)
val <E, A> Either<E, A>.value: A
  inline get() = when(this) {
    is Either.Left -> raise(value)
    is Either.Right -> value
  }
😕 1
c
isn't that just
.bind()
?
s
Yes, that's just
bind
but a lot of people judge Arrow solely on
bind
. And it just came up again in Scala.
c
Ah, do you mean this as a less-scary alternative?
s
I think Social Media, KotlinConf and nearing 2.0 release is scaring me 🤣
Yes, indeed
c
Good thing is, when we get context receivers, this can be added and
bind
can be deprecated (or just removed from the examples in the doc)
but yeah, it's weird seeing Raise4s becoming a thing in so little time when we're more or less stuck on this one feature
p
How would this differ to declaring
Copy code
@RaiseDSL
  public val <A> Either<Error, A>.value: A
    get() = when (this) {
      is Either.Left -> raise(value)
      is Either.Right -> value
    }
inside the
interface Raise<E>
definition?
👍 1
s
Uhm, nothing indeed.
p
(other than being unable to mark it
inline
)
s
I know something was up in interfaces, regular get is absolutely fine there!
p
I think the main benefit of context receivers here is being able to define these binds/properties outside the
Raise<E>
interface
k
Side note: Where do you lads get information around all these advanced Kotlin techniques?
c
Another name that would be even less surprising for new users (though more verbose):
Copy code
either {
    someOtherFunction().getOrRaise() // instead of .bind()
}
Personally I'm not a fan, because I'm accustomed to
.bind
now, but I can see how it would be more intuitive for beginners.
> Where do you lads get information around all these advanced Kotlin techniques? Do you have an example in some in particular you'd want to learn about? In general, in my case, it's: • reading the documentation website (though it's usually just basic use cases) • reading the KEEPs (lots to learn there about the overall design decisions and why they are the way they are) • reading the various slack channels here (it helps to learn about the maintainer's mindset) • purposefully writing complex stuff myself as part of my libs, and seeing where it goes / what I can do One example is how I learned about
provideDelegate
(which IMO is the DSL's most hidden secret): • I was looking at the Gradle DSL, and I was really confused as to how it worked • I tried to replicate it, but couldn't • I looked in the Gradle source code (CTRL B in IDEA) and found it was calling
provideDelegate
• Then I found the function in the Kotlin stdlib doc website, then I played with it quite a bit
🙏 1