diff --git a/fsharp/ygosim/src/Utils.fs b/fsharp/ygosim/src/Utils.fs index f241924..dbf2036 100644 --- a/fsharp/ygosim/src/Utils.fs +++ b/fsharp/ygosim/src/Utils.fs @@ -1,7 +1,15 @@ module Utils module List = - let setIndex index value list = - List.mapi (fun previous i -> + let setIndex index value = + List.mapi (fun i previous -> if i = index then value else previous) + + + let (.->) = setIndex + +module Lens = + open FSharpPlus.Lens + + let inline indexToLens index f (array: list<'a>) = f array.[index] <&> fun v -> List.setIndex index v array