mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
Added arrayFind
This commit is contained in:
parent
9e5c562d60
commit
11203f3a85
4 changed files with 16 additions and 1 deletions
BIN
lama-spec.pdf
BIN
lama-spec.pdf
Binary file not shown.
|
|
@ -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);
|
\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.}
|
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}}
|
\section{Unit \texttt{Collection}}
|
||||||
\label{sec:collection}
|
\label{sec:collection}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -78,3 +78,14 @@ public fun iteriArray (f, a) {
|
||||||
f (i, a [i])
|
f (i, a [i])
|
||||||
od
|
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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue