Skip to content

Instantly share code, notes, and snippets.

@alexdobry
Created July 29, 2020 10:57
Show Gist options
  • Save alexdobry/ac7f8c0d0e08a0fbe9b023638e51311d to your computer and use it in GitHub Desktop.
Save alexdobry/ac7f8c0d0e08a0fbe9b023638e51311d to your computer and use it in GitHub Desktop.
import Array "mo:base/Array";
type Question = {
#yesOrNo: {
question: Text;
solution: Bool;
};
#freeform: {
question: Text
};
};
type Answer = {
#yesOrNo: Bool;
#freeform: Text;
};
type Test = [(Question, ?Answer)];
func renderQuestion(question: Question): Text {
switch (question) {
case (#yesOrNo(q))
q.question;
case (#freeform(q))
q.question;
};
};
actor {
var questions: [Question] = [
#freeform({ question = "Welches Bier?" }),
#yesOrNo({ question = "Tabs or Spaces?"; solution = false })
];
var tests: [(Principal, Test)] = [];
// public func allQuestions() : async [Text] {
// Array.map(questions, renderQuestion)
// };
public func allQuestions() : async [Question] {
questions;
};
public func allTests() : async [(Principal, Test)] {
tests;
};
public shared { caller } func createTest(indicies: [Nat]) {
let test: Test = Array.map<Nat, (Question, ?Answer)>(indicies, func i = (questions[i], null));
// tests #= [(caller, test)];
tests := Array.append(tests, [(caller, test)]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment