Skip to content

Commit

Permalink
fixed bug with filter and tell that was throwing errors on nil params
Browse files Browse the repository at this point in the history
  • Loading branch information
dwringer committed Oct 29, 2016
1 parent 37f7c32 commit 11bac4b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion ClassDemo.Tanoa/classes/fnc_tell.sqf
Expand Up @@ -21,4 +21,6 @@ _methods = [[["_method_list", "_msg"],
_methods = [[["_x"], "not isNil ""_x"""] call fnc_lambdastr,
_methods] call fnc_filter;
_result = ([_instance] + _parameters) call (_methods select 0);
_result; // RETURN //////////////////////////////////////////////////////////
if (not isNil "_result") then {
_result;
}; // RETURN //////////////////////////////////////////////////////////
14 changes: 10 additions & 4 deletions ClassDemo.Tanoa/lambda/fnc_filter.sqf
@@ -1,6 +1,6 @@
/////////////////////////////// fnc_filter ///////////////////////// 2016-10-21
/* Filter an array by application of a predicate */
//////////////////////////////////////////////////////
/* Filter an array by application of a predicate */
/////////////////////////////////////////////////////
private [ //
"_fn", // Function [IN/A0/B0] //
"_arr", // Array [IN/A1/B1] ////
Expand All @@ -19,8 +19,14 @@ if ((count _this) == 3) then {
_acc = [];
for "_i" from 0 to ((count _arr) - 1) do {
_elt = _arr select _i;
if (([_elt] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
if (not isNil "_elt") then {
if (([_elt] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
};
} else {
if (([nil] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
};
};
};
_acc; // RETURN //////////////////////////////////////////////////////////////
4 changes: 3 additions & 1 deletion classes/fnc_tell.sqf
Expand Up @@ -21,4 +21,6 @@ _methods = [[["_method_list", "_msg"],
_methods = [[["_x"], "not isNil ""_x"""] call fnc_lambdastr,
_methods] call fnc_filter;
_result = ([_instance] + _parameters) call (_methods select 0);
_result; // RETURN //////////////////////////////////////////////////////////
if (not isNil "_result") then {
_result;
}; // RETURN //////////////////////////////////////////////////////////
14 changes: 10 additions & 4 deletions lambda/fnc_filter.sqf
@@ -1,6 +1,6 @@
/////////////////////////////// fnc_filter ///////////////////////// 2016-10-21
/* Filter an array by application of a predicate */
//////////////////////////////////////////////////////
/* Filter an array by application of a predicate */
/////////////////////////////////////////////////////
private [ //
"_fn", // Function [IN/A0/B0] //
"_arr", // Array [IN/A1/B1] ////
Expand All @@ -19,8 +19,14 @@ if ((count _this) == 3) then {
_acc = [];
for "_i" from 0 to ((count _arr) - 1) do {
_elt = _arr select _i;
if (([_elt] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
if (not isNil "_elt") then {
if (([_elt] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
};
} else {
if (([nil] + _extra_vars) call _fn) then {
_acc = _acc + [_elt];
};
};
};
_acc; // RETURN //////////////////////////////////////////////////////////////

0 comments on commit 11bac4b

Please sign in to comment.