Skip to content

Instantly share code, notes, and snippets.

@matthewcrews
Created November 4, 2022 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewcrews/4f8e0dc06b19edcbde4f5172f43e9c2b to your computer and use it in GitHub Desktop.
Save matthewcrews/4f8e0dc06b19edcbde4f5172f43e9c2b to your computer and use it in GitHub Desktop.
type All = All
type SliceIndex2D<'a, 'b when 'a : equality and 'b : equality>(values: seq<'a * 'b>) =
let values = Array.ofSeq values
member s.Item
with get (k1: 'a, _: All) =
values
|> Seq.filter (fun (a, _) -> a = k1)
member s.Item
with get (_: All, k2: 'b) =
values
|> Seq.filter (fun (_, b) -> b = k2)
let test =
SliceIndex2D [
1, 1
1, 5
1, 10
2, 5
2, 10
7, 1
8, 1
]
let x = test[1, All]
let y = test[All, 1]
for v in y do
printfn $"{v}"
(*
Prints:
(1, 1)
(7, 1)
(8, 1)
val it: unit = ()
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment