Macro serde_json_lodash::pull_all_by[][src]

macro_rules! pull_all_by {
    () => { ... };
    ($a:expr $(,)*) => { ... };
    ($a:expr, $b:expr $(,)*) => { ... };
    ($a:expr, $b:expr, $c:expr $(,)*) => { ... };
    ($a:expr, $b:expr, $c:expr, $($rest:tt)*) => { ... };
}

Description can be found in lodash pullAllBy

Examples:

#[macro_use] extern crate serde_json_lodash;
use serde_json::json;
let array = json!([{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]);
// conflict with fn, no implemented
// assert_eq!(
//   pull_all_by!(array, json!([{ 'x': 1 }, { 'x': 3 }]), "x"),
//   json!(0)
// );
assert_eq!(
  pull_all_by!(array, json!([{ 'x': 1 }, { 'x': 3 }]), |o| &o["x"]),
  json!([{ 'x': 2 }])
);

More examples:

assert_eq!(pull_all_by!(), json!(null));
assert_eq!(pull_all_by!(json!(null)), json!(null));
assert_eq!(pull_all_by!(json!(false)), json!(false));
assert_eq!(pull_all_by!(json!(0)), json!(0));
assert_eq!(pull_all_by!(json!("")), json!(""));
assert_eq!(pull_all_by!(json!([])), json!([]));
assert_eq!(pull_all_by!(json!([[]]), json!([])), json!([[]]));
assert_eq!(pull_all_by!(json!([{}]), json!({})), json!([{}]));
assert_eq!(pull_all_by!(json!([null]), json!([null])), json!([]));
assert_eq!(pull_all_by!(json!([null,0]), json!([null]), |x| &x), json!([0]));
assert_eq!(pull_all_by!(json!([null,0]), json!([null]), |x| &x["__non__"]), json!([]));
assert_eq!(pull_all_by!(json!({})), json!({}));