Please add a mapping for List.Indexed.
I need to filter an item based on the index but F# doesn't have a filteri method.
So I use Indexed but it is not supported.
...
| RemoveLineItem index ->
let items =
List.indexed model.Items
|> List.filter (fun (ix, item) -> not(ix = index))
|> List.map snd
I'm guessing the JS should be something like
const myList = ["foo", "bar"];
const indexed = myList.map((s,i) => [i, s]);
dotnet fable --version): 1.1.17If need a workaround for now:
module List =
let withIndices xs =
let items = xs |> Array.ofList
let length = items.Length
[ for i in 0 .. (length - 1) -> (i, items.[i]) ]
[1 .. 3]
|> List.withIndices
|> List.filter (fun (idx, item) -> idx <> 1) // [ (0, 1); (2; 3) ]
Thanks for the report! I also took the chance to clean up some functions within the collection modules. It will be fixed in the next release. For now, please use @Zaid-Ajaj polyfill :+1:
Note also that using many
List.orArray.intermediate steps can decrease performance specially with big collections as you have to recreate the whole structure every time. You can useSeq.for the intermediate steps, or in your case, you can easily polyfill the function you need:
module List =
let filteri f (xs: 't list) =
let mutable i = -1
List.filter (fun x -> i <- i + 1; f i x)
Most helpful comment
If need a workaround for now: