Added arrayFind

This commit is contained in:
Dmitry Boulytchev 2021-08-31 01:47:49 +03:00
parent 9e5c562d60
commit 11203f3a85
4 changed files with 16 additions and 1 deletions

Binary file not shown.

View file

@ -181,6 +181,10 @@ Array processing functions:
\descr{\lstinline|fun iteriArray (f, a)|}{Applies a function "\lstinline|f|" to each element of an array "\lstinline|a|" and its index (index first);
does not return a value.}
\descr{\lstinline|fun findArray (f, a)|}{Finds a value in an array "\lstinline|a|" which satisfies the predicate "\lstinline|f|". The
predicate must return integer value, treated as boolean. Returns "\lstinline|None|" if no element satisfies "\lstinline|f|" and
"\lstinline|Some (v)|" otherwise, where "\lstinline|v|"~--- the first value to satisfy "\lstinline|f|".}
\section{Unit \texttt{Collection}}
\label{sec:collection}

View file

@ -1 +1 @@
let version = "Version 1.10, 849162aa9, Wed Mar 24 18:51:25 2021 +0700"
let version = "Version 1.10, 9e5c562d6, Fri Aug 13 09:50:07 2021 +0300"

View file

@ -78,3 +78,14 @@ public fun iteriArray (f, a) {
f (i, a [i])
od
}
public fun findArray (f, a) {
var i = 0, found = false, value;
while i < a.length && found == false
do
found := f (value := a[i])
od;
if found then Some (value) else None fi
}