summaryrefslogtreecommitdiff
path: root/Jennisys/Utils.fs
diff options
context:
space:
mode:
Diffstat (limited to 'Jennisys/Utils.fs')
-rw-r--r--Jennisys/Utils.fs10
1 files changed, 10 insertions, 0 deletions
diff --git a/Jennisys/Utils.fs b/Jennisys/Utils.fs
index b7db5706..886d5868 100644
--- a/Jennisys/Utils.fs
+++ b/Jennisys/Utils.fs
@@ -119,6 +119,16 @@ let rec GenList n e =
else
e :: (GenList (n-1) e)
+// =======================================
+/// ensures: forall i :: 0 <= i < |lst| ==>
+/// if lst[i] = oldElem then
+/// ret[i] = newElem
+/// else
+/// ret[i] = lst[i]
+// =======================================
+let ListReplace oldElem newElem lst =
+ lst |> List.choose (fun e -> if e = oldElem then Some(newElem) else Some(e))
+
// ==========================
/// ensures: ret = elem in lst
// ==========================