Skip to content

Commit a9974e8

Browse files
committed
Add value variants for Dict functions
1 parent 7a635f1 commit a9974e8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/Aardvark.Base.FSharp/Interop/Dictionary.fs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,58 @@ module Dict =
143143

144144
let inline tryFind (key : 'k) (d : Dict<'k, 'v>) =
145145
match d.TryGetValue key with
146-
| (true, v) -> Some v
147-
| _ -> None
146+
| (true, v) -> Some v
147+
| _ -> None
148+
149+
let inline tryFindV (key : 'k) (d : Dict<'k, 'v>) =
150+
let mutable value = Unchecked.defaultof<_>
151+
if d.TryGetValue(key, &value) then ValueSome value
152+
else ValueNone
148153

149154
let inline ofSeq (elements : seq<'k * 'v>) =
150155
let result = Dict()
151156
for (k,v) in elements do
152157
result.[k] <- v
153158
result
154159

160+
let inline ofSeqV (elements : seq<struct('k * 'v)>) =
161+
let result = Dict()
162+
for (k,v) in elements do
163+
result.[k] <- v
164+
result
165+
155166
let inline ofList (elements : list<'k * 'v>) =
156167
ofSeq elements
157168

169+
let inline ofListV (elements : list<struct('k * 'v)>) =
170+
ofSeqV elements
171+
158172
let inline ofArray (elements : ('k * 'v)[]) =
159173
ofSeq elements
160174

175+
let inline ofArrayV (elements : struct('k * 'v)[]) =
176+
ofSeqV elements
177+
161178
let inline ofMap (elements : Map<'k, 'v>) =
162179
elements |> Map.toSeq |> ofSeq
163180

164181
let inline toSeq (d : Dict<'k, 'v>) =
165182
d |> Seq.map (fun (KeyValue(k,v)) -> k,v)
166183

184+
let inline toSeqV (d : Dict<'k, 'v>) =
185+
d |> Seq.map (fun (KeyValue(k,v)) -> struct(k,v))
186+
167187
let inline toList (d : Dict<'k, 'v>) =
168188
d |> toSeq |> Seq.toList
169189

190+
let inline toListV (d : Dict<'k, 'v>) =
191+
d |> toSeqV |> Seq.toList
192+
170193
let inline toArray (d : Dict<'k, 'v>) =
171-
d |> toSeq |> Seq.toArray
194+
d |> toSeq |> Seq.toArray
195+
196+
let inline toArrayV (d : Dict<'k, 'v>) =
197+
d |> toSeqV |> Seq.toArray
172198

173199
let inline toMap (d : Dict<'k, 'v>) =
174200
d |> toSeq |> Map.ofSeq

0 commit comments

Comments
 (0)