fsharp(ygosim): feat: added a helper to create a lens from an array index
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
a2243a035b
commit
e6dc6097f9
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue