https://kotlinlang.org logo
#arrow-contributors
Title
# arrow-contributors
p

pablisco

09/29/2021, 4:01 PM
I’ll start a new thread related to what @pakoito suggested on here.
Would it make sense to have shortcut bindings? We may be able to save having to create an Either if not needed. Something like:
Copy code
leftValue.bindLeft()
rightValue.bindRight()
And potentially the same for other types:
Copy code
nullable.bindOr { fallbackLeft }
option.bindOr { fallbackLeft }
result.bindOr { e -> someOtherLeftFrom(e) }
s

simon.vergauwen

09/29/2021, 4:05 PM
I’m actually really looking forward to multiple receivers
💯 2
Not sure if it’s relevant here but I often find myself wanting to use it in production projects
👌 1
To enhance the Either DSL in cool ways
p

pablisco

09/29/2021, 6:19 PM
Until we have MR, I’m trying to create this to provide similar restrictions that we can use to create a nicer API 🙂
s

simon.vergauwen

09/30/2021, 10:44 AM
I tried looking into the repo, but didn’t grasp the functionality yet I think 😅 Add a readme 😜
p

pablisco

09/30/2021, 10:52 AM
Yeah, it was just an intial try to use Meta 😅 The target functionality for the first prototype is defined here. Means that we can define custom Scope annotations. These can be used to tell the compiler that they can only be run on other functions annotated with that same annotation. Additionally, I would like to add some scope aware storage to share dependencies. Potentially typesafe 🤞
s

simon.vergauwen

09/30/2021, 11:05 AM
Ah okay, got it 👍 That is pretty cool for special DSLs, kinda like
RestrictSuspension
but without limiting suspension
💯 1
m

Marc

09/30/2021, 12:08 PM
I’m sorry for my ignorance but what cases are you thinking MR would be beneficial for? (any example?)
s

simon.vergauwen

09/30/2021, 2:35 PM
You can basically add domain specific DSLs to either, or have access to
bind
without wrapping in
either { }
. Here
ensureNotNull
comes from
either { }
, and this function can only be called inside
either<MyError, A>
but potentially you can write your whole domain code like this without having
Either
in the return type.
Copy code
@Context(EitherEffect<MyError, Any?>)
suspend fun ProductRepo.fetchUsers(): List<User> =
  ensureNotNull(fetch("SQL QUERY")) { MyError("Users not found") }
Or when you want to enable special DSLs because you typically want to enable special extension on
Either<E, A>
but you also want access to the
EitherEffect<E,  Any?>
. So currently we can only add special functions for the DSL inside Arrow Core but with multiple receivers you can add special DSL functions from outside the library also.
Copy code
@Context(EitherEffect<E, Any?>)
suspend fun <E> Either<E, A>.customDSL(): A {
  val a = this.bind()
  // DSL logic
  a
}

either<E, A> {
   1.right().customDSL()
}
m

Marc

09/30/2021, 3:11 PM
an what is a
EitherEffect
?
s

simon.vergauwen

09/30/2021, 3:12 PM
EitherEffect
is the receiver of the
either { }
dsl. Here
either<E, A> { this }
,
this
is
EitherEffect<E, Any?>
That’s why you can only call
customDSL
inside
either { }
3 Views