Skip to content

Commit

Permalink
- Added List.selectFirst1
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9984 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 30, 2011
1 parent 70c8c97 commit 8707c5b
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions Compiler/Util/List.mo
Expand Up @@ -5568,21 +5568,50 @@ public function selectFirst
output Boolean outSelect;
end SelectFunc;
algorithm
outElement := matchcontinue(inList, inFunc)
outElement := match (inList, inFunc)
local
ElementType e;
list<ElementType> rest;
Boolean b;

case (e :: _, _)
case (e :: rest, _)
equation
true = inFunc(e);
then
e;
b = inFunc(e);
e = Debug.bcallret2(not b,selectFirst,rest,inFunc,e);
then e;

case (e :: rest, _) then selectFirst(rest, inFunc);
end matchcontinue;
end match;
end selectFirst;

public function selectFirst1
"This function retrieves the first element of a list for which the passed
function evaluates to true."
input list<ElementType> inList;
input SelectFunc inFunc;
input ArgType1 arg1;
output ElementType outElement;

partial function SelectFunc
input ElementType inElement;
input ArgType1 arg;
output Boolean outSelect;
end SelectFunc;
algorithm
outElement := match (inList, inFunc, arg1)
local
ElementType e;
list<ElementType> rest;
Boolean b;

case (e :: rest, _, arg1)
equation
b = inFunc(e,arg1);
e = Debug.bcallret3(not b,selectFirst1,rest,inFunc,arg1,e);
then e;

end match;
end selectFirst1;

public function select1
"This function retrieves all elements of a list for which the given function
evaluates to true. The elements that evaluates to false are thus removed
Expand Down

0 comments on commit 8707c5b

Please sign in to comment.