diff --git a/lama-spec.pdf b/lama-spec.pdf index 2ba43769c..237cb3006 100644 Binary files a/lama-spec.pdf and b/lama-spec.pdf differ diff --git a/spec/08.standard_library.tex b/spec/08.standard_library.tex index f034ca658..207a0e207 100644 --- a/spec/08.standard_library.tex +++ b/spec/08.standard_library.tex @@ -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} diff --git a/src/version.ml b/src/version.ml index 849feb42d..ff511dc75 100644 --- a/src/version.ml +++ b/src/version.ml @@ -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" diff --git a/stdlib/Array.lama b/stdlib/Array.lama index 0ad3672d3..0e8fecb6b 100644 --- a/stdlib/Array.lama +++ b/stdlib/Array.lama @@ -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 +} \ No newline at end of file