Replies: 2 comments
-
The // Produces the same output
ResultContext.runCatching { "John".toNotBlankString() }
resultOf { "John".toNotBlankString() } |
Beta Was this translation helpful? Give feedback.
0 replies
-
This feature is live in Kotools Types 4.1.0. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
🤔 The problem
Using explicit types with builders returning an encapsulated value is sometimes difficult.
For example, assuming that we want to create a
Person
having afirstName
and alastName
properties of typeNotBlankString
, and anage
property of typeStrictlyPositiveInt
, we would have to do the following:As you can see, we need to unwrap the value of the result each time we want to create an explicit type (we are using the
getOrThrow
function in the example).💡 The idea
Introducing a new
resultOf
function that will encapsulate the computations of theResult
type within the givenblock
function could solve this issue.The
ResultContext
interface could implement the existing builders for a better adoption.But these builders should return the explicit type instead of an encapsulated one.
Here's an example for the
toNotBlankString
builder:Using the new
resultOf
function in the first example looks like this:🙏 Help needed
Please give this post a reaction if you are interested in this feature, or comment it below if you have any suggestion.
We would love to have your feedback!
Beta Was this translation helpful? Give feedback.
All reactions