Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
Exists
:trait Exists[A] { def apply(): Boolean }
object Exists extends Nope {
implicit def sure[A](implicit a: A): Exists[A] = new Exists[A] {
def apply() = true
}
}
trait Nope {
implicit def nope[A]: Exists[A] = new Exists[A] {
def apply() = false
}
}
def isEffect[T](implicit isIt: Exists[Effect[T]]) = isIt()
rho
issue
rho
only had Task
TypeTag
, which would need to also capture typeclass instances
trait TagHandler {
def success(x: Any): Unit
def failure(reason: Throwable): Unit
}
abstract class StandardTagHandler(val pfAllowedStates : PartialFunction[State, Unit]) extends TagHandler {
def sth_success(x : Any) : Unit
def success(x : Any) : Unit =
if (pfAllowedStates.isDefinedAt(state)) sth_success(x)
else resetToInit(s"$this called in unallowed state $state")
def failure(reason : Throwable) : Unit = {
resetToInit(s"$this failed with reason : $reason")
}
}
state : State
. i want to make this intermediate StandardTagHandler
class so I don't keep rewriting the state check boiler plate
State => Boolean
check or something like that
State1 <: State
etc, you could have a class StateTransition[A, B]
, have the method that does a state transition from From
to To
take an implicit StateTransition[From, To]
, and have a bunch of implicit object transitionFromTo extends StateTransition[From, To]
for the allowed transitions
case class Person(name: String, age: Int)
def updatePhoneCallWithCodiceStatistica(guid: String, codiceStatistica: String, fieldName: String): Future[Option[Future[Int]]] =
phoneCallsDAO.findByGuid(guid).map { ph =>
ph.map { call =>
val callUpdated = call.copy(codiceStatistica = Some(codiceStatistica))
phoneCallsDAO.update(call.id.get, callUpdated)
}
}