![]() ![]() Inline class Organizer(val value: String) import ĭata class ValidationError(val reason: String)Įlse Left(ValidationError("EventId needs to be bigger than 0, but found $value.")) They’ll return ValidationError in the Left side in the case a condition is not met, or an Event in the Right side if all conditions were met. To do so, we can create smart constructors that return Either. To create a proper Event, we need to validate that the properties meet certain conditions. Inline class Description(val value: String) Let’s continue with the domain from the previous blog post, which was Event. ![]() In this blog post, we’ll explore how we can use Either and Validated to achieve different goals. In a previous blog post about Functional Domain Modeling in Kotlin, we discussed how we can use data class, enum class, sealed class, and inline class to describe our business domain as accurately as possible to achieve more type-safety, maximize the use of the compiler with our domain, and thus, prevent bugs and reduce unit testing.Īt the end, we briefly discussed how we could use Arrow’s Either type to bring more type-safety into our business logic. This article was originally published at on April 13, 2021. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |