Rabobank-Archive / rule-engine

A rule engine supporting forward chaining
MIT License
47 stars 5 forks source link

Create monadic EvaluationResult to replace Option #54

Closed jhkuperus closed 8 years ago

jhkuperus commented 8 years ago

For proper error handling, we are going to need an extension over the Option type. Preferably, we'd have something like this:

sealed trait EvaluationResult[+A]

case class Some[+A](val value: A) extends EvaluationResult[A]
case class None[+A] extends EvaluationResult[A]
case class Error[+A](val exception: Exception) extends EvaluationResult[A]

This will allow us to differentiate between the cases in which a value simply was not available and when an exception occurred preventing the proper completion of an evaluation.

NRBPerdijk commented 8 years ago

I think we can achieve the desired behaviour by wrapping the option in a Try or Future.

jhkuperus commented 8 years ago

:) Way to rein me in there trying to create something that's basically expressed as easily as this:

type EvaluationResult[A] = Try[Option[A]]

I'll have to think about the Future you mention, it may actually open the door to allowing evaluations which are considered to be asynchronous.

NRBPerdijk commented 8 years ago

Sometimes the wheel has already been invented! ^^