Hi :wave:. I'm trying to use `Validated` instead `...
# arrow
s
Hi 👋. I'm trying to use
Validated
instead
require
for validation when constructing an object.
Copy code
class Probability private constructor(val value: Double) {
  companion object {
    fun create(value: Double) =
      if (value > 0.00 && value < 1.00) Probability(value).valid()
      else ValidationError.ProbabilityOutOfBounds("Probability must be between 0.00 and 1.00").invalid()
  }
}
I'm struggling to find the best way to structure it in a given context. Typical use case for `Probability`:
Copy code
val fsmIdentifiers =
  listOf(
    FsmIdentifier(
      key = "first",
      mProbability = Probability(0.95),
      uProbability = Probability(0.1),
      compare = ::jaroWinklerDistance
    ),
    FsmIdentifier(
      key = "last",
      mProbability = Probability(0.99),
      uProbability = Probability(0.01),
      compare = ::jaroWinklerDistance
    ),
    FsmIdentifier(
      key = "middle",
      mProbability = Probability(0.90),
      uProbability = Probability(0.1),
      compare = ::jaroWinklerDistance
    ),
......
)
As you see, the
Probability
is created as part of the
FsmIdentifier
(and other similar identifiers). Any suggestion on how to handle the creation with
Validated
in this context cleanly, without making the code look overwhelmingly verbose?
s
s
Great. Thank you!