1
Fork 0

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:
Matei Adriel 2019-12-15 15:20:20 +02:00 committed by prescientmoon
parent a2243a035b
commit e6dc6097f9
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View file

@ -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