F # slice array by indices

How can I reload. [] for an F # array to slice an array based on an arbitrary array of indices?

For example:

let x = [|1..10|]; let indx = [|4;1|]; 

though

 [| for i in indx ->x.[i]|] 

it would be better to use x.[indx] directly.

+2
f #
Mar 01 '10 at 15:49
source share
1 answer

You can always write an F # extension method to get closer to the syntax

 let a = [| 1..10 |] let idx = [|4;1|] type 'T ``[]`` with //' member this.Slice(indices:int array) = [| for i in indices -> this.[i] |] printfn "%A" (a.Slice idx) 

but since there is already a pointer in the arrays, it does not appear where you can overload / change it.

+5
Mar 01 '10 at 16:05
source share



All Articles