Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ndc_lib/src/stdlib/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,20 @@ mod inner {
}
}

Err(anyhow!("find did not find anything").into())
Err(anyhow!("locate did not find anything").into())
}

/// Returns the first index of the element or produces an error
#[function(name = "locate")]
pub fn locate_element(seq: &mut Sequence, element: &Value) -> EvaluationResult {
let iterator = mut_seq_to_iterator(seq);
for (idx, el) in iterator.enumerate() {
if &el == element {
return Ok(Value::from(idx));
}
}

Err(anyhow!("locate did not find anything").into())
}

/// Returns `true` if the `predicate` is true for none of the elements in `seq`.
Expand Down