Question

com.softinio.verdict4s.algebra.Question$package.Question
object Question

Constructors for every question type, and the combinators that change how an answer is read.

Every constructor returns a validated Question[A]: it never throws, and problems accumulate rather than stopping at the first. A is what the answer decodes to -- NoulAnswer, ChoiceAnswer[D] for an option type D, or ScoreAnswer -- and map or emap turn it into a type of your own.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Question.type

Members list

Type members

Classlikes

final case class Spec[A](wire: QuestionSpec, decode: Answer => Either[Verdict4sError, A])

A validated question paired with its answer decoder.

A validated question paired with its answer decoder.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def choice[A](instructions: String)(using options: Options[A]): Question[ChoiceAnswer[A]]

Pick one option from a set, answering in the caller's own type.

Pick one option from a set, answering in the caller's own type.

Attributes

inline def choiceOf[A](instructions: String)(using SumOf[A]): Question[ChoiceAnswer[A]]

Pick one option, deriving the set from an enum on the spot.

Pick one option, deriving the set from an enum on the spot.

Equivalent to choice[A] with a derived Options, for an enum that does not carry a derives Options clause.

Attributes

Pick one option from a set whose names are only known at runtime.

Pick one option from a set whose names are only known at runtime.

Attributes

def invalid[A](field: String, details: String): Question[A]

A question that is already known to be invalid. Mostly useful in tests.

A question that is already known to be invalid. Mostly useful in tests.

Attributes

def noul(instructions: String): Question[NoulAnswer]

A yes/no question.

A yes/no question.

Attributes

def noul(instructions: String, ifTrue: String, ifFalse: String): Question[NoulAnswer]

A yes/no question that says what a yes and a no mean.

A yes/no question that says what a yes and a no mean.

Attributes

def noulOf(instructions: Instructions, criteria: Option[NoulCriteria] = ...): Question[NoulAnswer]

A yes/no question built from structured instructions.

A yes/no question built from structured instructions.

Attributes

def raw[A](questionType: String, body: JsonObject)(decode: Answer => Either[Verdict4sError, A]): Question[A]

Send a question shape this release does not model.

Send a question shape this release does not model.

Forward compatibility: if the service grows a fourth question type, this lets you use it immediately rather than wait for a library version.

Attributes

def score(instructions: String, levels: Seq[String]): Question[ScoreAnswer]

Rate against ordered levels, lowest first.

Rate against ordered levels, lowest first.

Attributes

def scoreOf[A](instructions: String)(using levels: Levels[A]): Question[ScoreAnswer]

Rate against levels described by a Levels instance.

Rate against levels described by a Levels instance.

Attributes

inline def scoreOfEnum[A](instructions: String)(using SumOf[A]): Question[ScoreAnswer]

Rate against levels derived from an enum on the spot.

Rate against levels derived from an enum on the spot.

Attributes

Extensions

Extensions

extension [A](q: Question[A])
def emap[B](f: A => Either[Verdict4sError, B]): Question[B]

Post-process the answer, with the option to reject it.

Post-process the answer, with the option to reject it.

Use this when your type cannot represent every answer the service might give — a failure surfaces as a Verdict4sError, exactly as a malformed response would.

Attributes

def map[B](f: A => B): Question[B]

Post-process the answer into your own type.

Post-process the answer into your own type.

The wire request is untouched; only the way the answer is read changes.

Attributes

The question as it will be sent, if it is valid.

The question as it will be sent, if it is valid.

Attributes

Collapse accumulated failures into one raisable error.

Collapse accumulated failures into one raisable error.

Attributes

The accumulated validation result.

The accumulated validation result.

Attributes