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 Utils
|
||||||
|
|
||||||
module List =
|
module List =
|
||||||
let setIndex index value list =
|
let setIndex index value =
|
||||||
List.mapi (fun previous i ->
|
List.mapi (fun i previous ->
|
||||||
if i = index then value
|
if i = index then value
|
||||||
else previous)
|
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