What's a good name for an alternative to the `Resu...
# arrow
c
What's a good name for an alternative to the
Result
type to avoid name clashes with the stdlib?
p
I used
Resultus
. It was kinda sus and didn't work out either 🐕
k
What about Try?
c
Personally find ‘Try’ confusing, it’s been tainted by
try
.
I’m using ‘Result’ and dealing with the name clash, prioritizing the conceptual correctness of the name.
s
Are you just typealiasing Try<T> or Either<Exception, T>? I’ve not found much application for a specific Result type and tend to just use Either.
c
I have a single
Failure
type that I want to use everywhere, so I want to
typealias ???<T> = Either<Failure, T>
Result
is a great name, but since this alias will have the same generics signature as the one in the stdlib, it's too easy to mistake them
s
Result really is a great name for that. I tend to use DomainError as my base failure type so DomainResult is probably what I would reach for if I wanted that type. Outcome is maybe the best direct synonym I can think of.
c
Outcome
is indeed pretty good 🤔
Bonus point:
out
is not a keyword (unlike
in
), and it's a pretty good builder name:
Copy code
fun ping() = out {
s
I’m probably in the minority of Kotlin devs (I’m still mostly writing Java) but I tend to like a longer but more descriptive name anyway. Maybe
outcomeOf
I never thought about
out
not being a keyword though!
c
To me,
outcomeOf()
takes a single value or a vararg (e.g.
listOf(1)
,
flowOf(1)
) and
outcome {}
takes a lambda that actually does the computation (e.g.
either {}
,
flow {}
)
p
s
That’s a good point! I’m not the one to ask about Kotlin idiomatic naming ;)
c
I really like that Kotlin tries its best not to make stuff like that keywords
I constantly stumble upon not being able to name a variable
in
, imagine if we couldn't name a variable
open
or
data
😨