;-- TIME_STAMP 2020-03-23 09:14:45 #cs ========================================================================================== FUNCTIONS _ArrayFilterIt Iteriert über das Array und erstellt ein Ergebnisarray mit den gültigen Werten der Bedingung _ArrayKeepItIf Iteriert über das Array und behält nur die gültigen Werte der Bedingung _ArrayAllIt Prüft ob für alle Einträge des Arrays die Bedingung zutrifft _ArrayAnyIt Prüft ob für mindestens einen Eintrag des Arrays die Bedingung zutrifft _ArrayMapIt Iteriert über das Array und erstellt ein Ergebnisarray mit den Ergebnissen der Operation _ArrayApplyIt Iteriert über das Array und führt die Operation für jedes Element des Arrays aus ========================================================================================= /FUNCTIONS #ce ;=================================================================================================== ; Function Name....: _ArrayFilterIt($_ar, $_pred) ; Description......: Returns a new array with all the items of $_ar that fulfilled the predicate $_pred. ; Parameter(s).....: $_ar The array to filter ; .................: $_pred The predicate for filtering. The condition must return a Boolean result. ; .................: The value "&it" is used to correspond to the item to be iterated. ; .................: i.e. '&it > 10 and &it < 20' or 'StringLen("&it") = 3 and StringMid("&it", 1, 1) = "b"' ; .................: The predicate can also refer to a function with the parameter "&it". ; .................: i.e. '_yield("&it")' ; Return Value(s)..: The result array ;=================================================================================================== Func _ArrayFilterIt(ByRef $_ar, $_pred) Local $matches[UBound($_ar)], $count = 0 For $i = 0 To UBound($_ar) -1 If Execute(StringReplace($_pred, "&it", $_ar[$i])) Then $matches[$count] = $_ar[$i] $count += 1 EndIf Next If $count > 0 Then ReDim $matches[$count] Return $matches EndFunc ;=================================================================================================== ; Function Name....: _ArrayKeepItIf($_ar, $_pred) ; Description......: Same as "_ArrayFilterIt", but changes the array itself. ; Return Value(s)..: none ;=================================================================================================== Func _ArrayKeepItIf(ByRef $_ar, $_pred) $_ar = _ArrayFilterIt($_ar, $_pred) EndFunc ;=================================================================================================== ; Function Name....: _ArrayAllIt($_ar, $_pred) ; Description......: Checks whether the condition applies to each element of the array. ; Parameter(s).....: $_ar The array to check ; .................: $_pred The predicate for checking. The condition must return a Boolean result. ; .................: The value "&it" is used to correspond to the item to be iterated. ; .................: i.e. '&it > 10 and &it < 20' or 'StringLen("&it") = 3 and StringMid("&it", 1, 1) = "b"' ; .................: The predicate can also refer to a function with the parameter "&it". ; .................: i.e. '_yield("&it")' ; Return Value(s)..: True or False ;=================================================================================================== Func _ArrayAllIt(ByRef $_ar, $_pred) Local $count = 0 For $i = 0 To UBound($_ar) -1 If Execute(StringReplace($_pred, "&it", $_ar[$i])) Then $count += 1 Next Return ( $count = UBound($_ar) ) EndFunc ;=================================================================================================== ; Function Name....: _ArrayAnyIt($_ar, $_pred) ; Description......: Checks whether the condition applies to minimum one element of the array. ; Parameter(s).....: $_ar The array to check ; .................: $_pred The predicate for checking. The condition must return a Boolean result. ; .................: The value "&it" is used to correspond to the item to be iterated. ; .................: i.e. '&it > 10 and &it < 20' or 'StringLen("&it") = 3 and StringMid("&it", 1, 1) = "b"' ; .................: The predicate can also refer to a function with the parameter "&it". ; .................: i.e. '_yield("&it")' ; Return Value(s)..: True or False ;=================================================================================================== Func _ArrayAnyIt(ByRef $_ar, $_pred) For $i = 0 To UBound($_ar) -1 If Execute(StringReplace($_pred, "&it", $_ar[$i])) Then Return True Next Return False EndFunc ;=================================================================================================== ; Function Name....: _ArrayMapIt($_ar, $_op) ; Description......: Returns a new array with the results of op proc applied to every item in the array. ; Parameter(s).....: $_ar The array for whose elements the operation is performed. ; .................: $_op The operation to be performed. ; .................: The value "&it" is used to correspond to the item to be iterated. ; .................: i.e. '&it * 4' or '&it / 3' or '"pre" & "&it" & "past"' ; Return Value(s)..: The new array ;=================================================================================================== Func _ArrayMapIt(ByRef $_ar, $_op) Local $aRes[UBound($_ar)] For $i = 0 To UBound($aRes) -1 $aRes[$i] = Execute(StringReplace($_op, "&it", $_ar[$i])) Next Return $aRes EndFunc ;=================================================================================================== ; Function Name....: _ArrayApplyIt($_ar, $_op) ; Description......: Same as "_ArrayMapIt", but changes the array itself. ; Return Value(s)..: none ;=================================================================================================== Func _ArrayApplyIt(ByRef $_ar, $_op) $_ar = _ArrayMapIt($_ar, $_op) Return EndFunc