MCPcopy Create free account
hub / github.com/hashintel/hash / parse_experiment

Function parse_experiment

libs/error-stack/examples/demo.rs:23–49  ·  view source on GitHub ↗
(description: &str)

Source from the content-addressed store, hash-verified

21 reason = "false-positive, try_fold is fail-fast, our implementation is fail-slow"
22)]
23fn parse_experiment(description: &str) -> Result<Vec<(u64, u64)>, Report<ParseExperimentError>> {
24 let values = description
25 .split(' ')
26 .map(|value| {
27 value
28 .parse::<u64>()
29 .attach_with(|| format!("{value:?} could not be parsed as experiment"))
30 })
31 .map(|value| value.map(|ok| (ok, 2 * ok)))
32 .fold(Ok(vec![]), |accum, value| match (accum, value) {
33 (Ok(mut accum), Ok(value)) => {
34 accum.push(value);
35
36 Ok(accum)
37 }
38 (Ok(_), Err(err)) => Err(err.expand()),
39 (Err(accum), Ok(_)) => Err(accum),
40 (Err(mut accum), Err(err)) => {
41 accum.push(err);
42
43 Err(accum)
44 }
45 })
46 .change_context(ParseExperimentError)?;
47
48 Ok(values)
49}
50
51#[derive(Debug)]
52struct ExperimentError;

Callers 1

start_experimentsFunction · 0.85

Calls 8

OkInterface · 0.85
ErrInterface · 0.85
splitMethod · 0.80
expandMethod · 0.80
pushMethod · 0.65
change_contextMethod · 0.45
mapMethod · 0.45
attach_withMethod · 0.45

Tested by

no test coverage detected