import { AnswersQuestions, UsesAbilities } from '../actor'; import { Answerable } from '../Answerable'; import { Question } from '../Question'; /** * @experimental */ export class Transform implements Question> { static the(questions: Answerable | Array>, transformation: (...answers: AT[]) => OT) { return new Transform([].concat(questions), transformation); } constructor( private readonly questions: Array>, private readonly transformation: (...answers: Answer_Type[]) => Output_Type, private readonly description: string = `a transformed answer`, ) { } /** * @desc * Overrides the default {@link Transform#toString} representation of this object. * * @param {string} description * @returns {Transform} */ as(description: string) { return new Transform(this.questions, this.transformation, description); } answeredBy(actor: AnswersQuestions & UsesAbilities): Promise { return Promise.all(this.questions.map(question => actor.answer(question))) .then(answers => this.transformation(...answers)); } toString() { return this.description; } }