From e62df6cbed7e4e111092cb08f53a8cb38b4883b7 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 16 Oct 2020 21:02:16 +0800 Subject: [PATCH] Remove none for array. --- doc/src/language/arrays.md | 1 - src/packages/array_basic.rs | 35 ----------------------------------- 2 files changed, 36 deletions(-) diff --git a/doc/src/language/arrays.md b/doc/src/language/arrays.md index 7016a19c..d687e002 100644 --- a/doc/src/language/arrays.md +++ b/doc/src/language/arrays.md @@ -54,7 +54,6 @@ The following methods (mostly defined in the [`BasicArrayPackage`][packages] but | `reduce` | 1) [function pointer] to accumulator function (usually a [closure]),
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:
1st parameter: accumulated value ([`()`] initially),
2nd parameter: array item,
3rd parameter: _(optional)_ offset index | | `reduce_rev` | 1) [function pointer] to accumulator function (usually a [closure]),
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:
1st parameter: accumulated value ([`()`] initially),
2nd parameter: array item,
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:
1st parameter: array item,
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:
1st parameter: array item,
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:
1st parameter: array item,
2nd parameter: _(optional)_ offset index | | `sort` | [function pointer] to a comparison function (usually a [closure]) | sorts the array with a comparison function:
1st parameter: first item,
2nd parameter: second item,
return value: `INT` < 0 if first < second, > 0 if first > second, 0 if first == second | diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index de5bdfcc..826a2196 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -79,7 +79,6 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, { lib.set_raw_fn("reduce_rev", &[TypeId::of::(), TypeId::of::(), TypeId::of::()], reduce_rev_with_initial); lib.set_raw_fn("some", &[TypeId::of::(), TypeId::of::()], some); lib.set_raw_fn("all", &[TypeId::of::(), TypeId::of::()], all); - lib.set_raw_fn("none", &[TypeId::of::(), TypeId::of::()], none); lib.set_raw_fn("sort", &[TypeId::of::(), TypeId::of::()], sort); // Merge in the module at the end to override `+=` for arrays @@ -364,40 +363,6 @@ fn all( Ok(true.into()) } -fn none( - engine: &Engine, - lib: &Module, - args: &mut [&mut Dynamic], -) -> Result> { - let list = args[0].read_lock::().unwrap(); - let filter = args[1].read_lock::().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( engine: &Engine, lib: &Module,