Daphne has been working on a system to run and record the results of her experiments. Some of the code has become a bit verbose and repetitive, so she's asked you to write some use expressions to help clean it up.
with_retry functionSometimes experiments can fail due to a one-off mistake, so if an experiment fails Daphne wants to retry it again to see if it works the second time.
Define the with_retry function that takes a result returning function as an argument.
If the function returns an Ok value then with_retry should return that value.
If the function returns an Error value then with_retry should call the function again and return the result of that call.
Daphne will use the function like this:
pub fn main() {
use <- with_retry
// Perform the experiment here
}record_timing functionDaphne records how long each experiment takes to run by calling a time logging function before and after each experiment.
Define the record_timing function that takes two arguments:
Nil.record_timing should call the time logging function, then call the experiment function, then call the time logging function again, and finally return the result of the experiment function.
Daphne will use the function like this:
pub fn main() {
use <- record_timing(time_logger)
// Perform the experiment here
}run_experiment functionExperiments are made up of three phases. The setup, the action, and the recording. All three phases return results, and each phase needs the successful result of the previous phase to run.
Define the run_experiment function that takes four arguments:
String.Ok value of the setup function as an argument and returns a result.Ok value of the setup and action functions as arguments and returns a result.If all three functions succeed then run_experiment should return Ok(#(experiment_name, recording_data)).
If any of the functions return an Error value then run_experiment should return that value.
Daphne will use the function like this:
pub fn main() {
use setup_data, action_data <- run_experiment("Test 1", setup, action)
// Record the results here
}Daphne has been working on a system to run and record the results of her experiments. Some of the code has become a bit verbose and repetitive, so she's asked you to write some use expressions to help clean it up.
with_retry functionSometimes experiments can fail due to a one-off mistake, so if an experiment fails Daphne wants to retry it again to see if it works the second time.
Define the with_retry function that takes a result returning function as an argument.
If the function returns an Ok value then with_retry should return that value.
If the function returns an Error value then with_retry should call the function again and return the result of that call.
Daphne will use the function like this:
pub fn main() {
use <- with_retry
// Perform the experiment here
}record_timing functionDaphne records how long each experiment takes to run by calling a time logging function before and after each experiment.
Define the record_timing function that takes two arguments:
Nil.record_timing should call the time logging function, then call the experiment function, then call the time logging function again, and finally return the result of the experiment function.
Daphne will use the function like this:
pub fn main() {
use <- record_timing(time_logger)
// Perform the experiment here
}run_experiment functionExperiments are made up of three phases. The setup, the action, and the recording. All three phases return results, and each phase needs the successful result of the previous phase to run.
Define the run_experiment function that takes four arguments:
String.Ok value of the setup function as an argument and returns a result.Ok value of the setup and action functions as arguments and returns a result.If all three functions succeed then run_experiment should return Ok(#(experiment_name, recording_data)).
If any of the functions return an Error value then run_experiment should return that value.
Daphne will use the function like this:
pub fn main() {
use setup_data, action_data <- run_experiment("Test 1", setup, action)
// Record the results here
}