Remove none for array.
This commit is contained in:
parent
29374a8ce7
commit
e62df6cbed
@ -54,7 +54,6 @@ The following methods (mostly defined in the [`BasicArrayPackage`][packages] but
|
|||||||
| `reduce` | 1) [function pointer] to accumulator function (usually a [closure]),<br/>2) _(optional)_ [function pointer] to function (usually a [closure]) that provides the initial value | reduces the array into a single value via the accumulator function:<br/>1st parameter: accumulated value ([`()`] initially),<br/>2nd parameter: array item,<br/>3rd parameter: _(optional)_ offset index |
|
| `reduce` | 1) [function pointer] to accumulator function (usually a [closure]),<br/>2) _(optional)_ [function pointer] to function (usually a [closure]) that provides the initial value | reduces the array into a single value via the accumulator function:<br/>1st parameter: accumulated value ([`()`] initially),<br/>2nd parameter: array item,<br/>3rd parameter: _(optional)_ offset index |
|
||||||
| `reduce_rev` | 1) [function pointer] to accumulator function (usually a [closure]),<br/>2) _(optional)_ [function pointer] to function (usually a [closure]) that provides the initial value | reduces the array (in reverse order) into a single value via the accumulator function:<br/>1st parameter: accumulated value ([`()`] initially),<br/>2nd parameter: array item,<br/>3rd parameter: _(optional)_ offset index |
|
| `reduce_rev` | 1) [function pointer] to accumulator function (usually a [closure]),<br/>2) _(optional)_ [function pointer] to function (usually a [closure]) that provides the initial value | reduces the array (in reverse order) into a single value via the accumulator function:<br/>1st parameter: accumulated value ([`()`] initially),<br/>2nd parameter: array item,<br/>3rd parameter: _(optional)_ offset index |
|
||||||
| `some` | [function pointer] to predicate (usually a [closure]) | returns `true` if any item returns `true` when called with the predicate function:<br/>1st parameter: array item,<br/>2nd parameter: _(optional)_ offset index |
|
| `some` | [function pointer] to predicate (usually a [closure]) | returns `true` if any item returns `true` when called with the predicate function:<br/>1st parameter: array item,<br/>2nd parameter: _(optional)_ offset index |
|
||||||
| `none` | [function pointer] to predicate (usually a [closure]) | returns `true` if no item returns `true` when called with the predicate function:<br/>1st parameter: array item,<br/>2nd parameter: _(optional)_ offset index |
|
|
||||||
| `all` | [function pointer] to predicate (usually a [closure]) | returns `true` if all items return `true` when called with the predicate function:<br/>1st parameter: array item,<br/>2nd parameter: _(optional)_ offset index |
|
| `all` | [function pointer] to predicate (usually a [closure]) | returns `true` if all items return `true` when called with the predicate function:<br/>1st parameter: array item,<br/>2nd parameter: _(optional)_ offset index |
|
||||||
| `sort` | [function pointer] to a comparison function (usually a [closure]) | sorts the array with a comparison function:<br/>1st parameter: first item,<br/>2nd parameter: second item,<br/>return value: `INT` < 0 if first < second, > 0 if first > second, 0 if first == second |
|
| `sort` | [function pointer] to a comparison function (usually a [closure]) | sorts the array with a comparison function:<br/>1st parameter: first item,<br/>2nd parameter: second item,<br/>return value: `INT` < 0 if first < second, > 0 if first > second, 0 if first == second |
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
|
|||||||
lib.set_raw_fn("reduce_rev", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>(), TypeId::of::<FnPtr>()], reduce_rev_with_initial);
|
lib.set_raw_fn("reduce_rev", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>(), TypeId::of::<FnPtr>()], reduce_rev_with_initial);
|
||||||
lib.set_raw_fn("some", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], some);
|
lib.set_raw_fn("some", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], some);
|
||||||
lib.set_raw_fn("all", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], all);
|
lib.set_raw_fn("all", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], all);
|
||||||
lib.set_raw_fn("none", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], none);
|
|
||||||
lib.set_raw_fn("sort", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], sort);
|
lib.set_raw_fn("sort", &[TypeId::of::<Array>(), TypeId::of::<FnPtr>()], sort);
|
||||||
|
|
||||||
// Merge in the module at the end to override `+=` for arrays
|
// Merge in the module at the end to override `+=` for arrays
|
||||||
@ -364,40 +363,6 @@ fn all(
|
|||||||
Ok(true.into())
|
Ok(true.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn none(
|
|
||||||
engine: &Engine,
|
|
||||||
lib: &Module,
|
|
||||||
args: &mut [&mut Dynamic],
|
|
||||||
) -> Result<bool, Box<EvalAltResult>> {
|
|
||||||
let list = args[0].read_lock::<Array>().unwrap();
|
|
||||||
let filter = args[1].read_lock::<FnPtr>().unwrap();
|
|
||||||
|
|
||||||
for (i, item) in list.iter().enumerate() {
|
|
||||||
if filter
|
|
||||||
.call_dynamic(engine, lib, None, [item.clone()])
|
|
||||||
.or_else(|err| match *err {
|
|
||||||
EvalAltResult::ErrorFunctionNotFound(_, _) => {
|
|
||||||
filter.call_dynamic(engine, lib, None, [item.clone(), (i as INT).into()])
|
|
||||||
}
|
|
||||||
_ => Err(err),
|
|
||||||
})
|
|
||||||
.map_err(|err| {
|
|
||||||
Box::new(EvalAltResult::ErrorInFunctionCall(
|
|
||||||
"filter".to_string(),
|
|
||||||
err,
|
|
||||||
Position::none(),
|
|
||||||
))
|
|
||||||
})?
|
|
||||||
.as_bool()
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
return Ok(false.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(true.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reduce(
|
fn reduce(
|
||||||
engine: &Engine,
|
engine: &Engine,
|
||||||
lib: &Module,
|
lib: &Module,
|
||||||
|
Loading…
Reference in New Issue
Block a user