1+ namespace FSharpPlus.Data
2+
3+ open System
4+ open System.Runtime .InteropServices
5+ open System.ComponentModel
6+ open System.Collections .Generic
7+ open FSharpPlus
8+
9+ [<AutoOpen>]
10+ module Auto =
11+ let icollection value =
12+ {
13+ new ICollection< 't> with
14+ member _.Contains ( item : 't ) = obj.ReferenceEquals ( item, value)
15+ member _.GetEnumerator () = ( Seq.initInfinite ( fun _ -> value)). GetEnumerator () :> System .Collections .IEnumerator
16+ member _.GetEnumerator () = ( Seq.initInfinite ( fun _ -> value)). GetEnumerator () : IEnumerator < 't >
17+ member _.IsReadOnly = true
18+
19+ member _.Add ( _item : 't ) : unit = raise ( System.NotImplementedException())
20+ member _.Clear () : unit = raise ( System.NotImplementedException())
21+ member _.CopyTo ( _array : 't [], _arrayIndex : int ) : unit = raise ( System.NotImplementedException())
22+ member _.Count : int = raise ( System.NotImplementedException())
23+ member _.Remove ( _item : 't ): bool = raise ( System.NotImplementedException())
24+ }
25+
26+ type DefaultableDict < 'TKey , 'TValue >( source : 'TValue ) =
27+ interface IDictionary< 'TKey, 'TValue> with
28+ member _.TryGetValue ( _key : 'TKey , value : byref < 'TValue >) = value <- source; true
29+ member _.Count =
30+ if typeof< 'TKey>. IsValueType then
31+ if typeof< 'TKey> = typeof< bool> then 2
32+ else
33+ let s = sizeof< 'TKey>
34+ if s < 4 then pown 2 ( sizeof< 'TKey> * 8 )
35+ else - 1
36+ elif typeof< 'TKey> = typeof< unit> then 1
37+ else - 1
38+ member _.ContainsKey ( _key : 'TKey ) = true
39+ member _.Contains ( item : KeyValuePair < 'TKey , 'TValue >) = obj.ReferenceEquals ( item.Value, source)
40+ member _.GetEnumerator () = invalidOp " Key set is potentially infinite." : System.Collections.IEnumerator
41+ member _.GetEnumerator () = invalidOp " Key set is potentially infinite." : IEnumerator< KeyValuePair< 'TKey, 'TValue>>
42+ member _.IsReadOnly = true
43+ member _.Values = icollection source
44+ member _.Item
45+ with get ( _key : 'TKey ) : 'TValue = source
46+ and set ( _key : 'TKey ) ( _ : 'TValue ) : unit = raise ( System.NotImplementedException())
47+
48+ member _.Add ( _key : 'TKey , _value : 'TValue ) : unit = raise ( System.NotImplementedException())
49+ member _.Add ( _item : KeyValuePair < 'TKey , 'TValue >) : unit = raise ( System.NotImplementedException())
50+ member _.Clear () : unit = raise ( System.NotImplementedException())
51+ member _.CopyTo ( _arr : KeyValuePair < 'TKey , 'TValue > [], _arrayIndex : int ) : unit = raise ( System.NotImplementedException())
52+ member _.Keys : ICollection < 'TKey > = raise ( System.NotImplementedException())
53+ member _.Remove ( _key : 'TKey ) : bool = raise ( System.NotImplementedException())
54+ member _.Remove ( _item : KeyValuePair < 'TKey , 'TValue >) : bool = raise ( System.NotImplementedException())
55+ (*
56+ interface IReadOnlyDictionary<'TKey, 'TValue> with
57+ member _.TryGetValue (_key: 'TKey, value: byref<'TValue>) = value <- source; true
58+ member _.Count =
59+ if typeof<'TKey>.IsValueType then
60+ if typeof<'TKey> = typeof<bool> then 2
61+ else
62+ let s = sizeof<'TKey>
63+ if s < 4 then pown 2 (sizeof<'TKey> * 8)
64+ else -1
65+ elif typeof<'TKey> = typeof<unit> then 1
66+ else -1
67+ member _.ContainsKey (_key: 'TKey) = true
68+ // member _.Contains (item: KeyValuePair<'TKey,'TValue>) = obj.ReferenceEquals (item.Value, source)
69+ member _.GetEnumerator () = invalidOp "Key set is potentially infinite." : System.Collections.IEnumerator
70+ member _.GetEnumerator () = invalidOp "Key set is potentially infinite." : IEnumerator<KeyValuePair<'TKey,'TValue>>
71+ // member _.IsReadOnly = true
72+ member _.Values = icollection source
73+ member _.Item
74+ with get (_key: 'TKey) : 'TValue = source
75+ // and set (_key: 'TKey) (_: 'TValue) : unit = raise (System.NotImplementedException())
76+
77+ // member _.Add (_key: 'TKey, _value: 'TValue) : unit = raise (System.NotImplementedException())
78+ // member _.Add (_item: KeyValuePair<'TKey,'TValue>) : unit = raise (System.NotImplementedException())
79+ // member _.Clear () : unit = raise (System.NotImplementedException())
80+ // member _.CopyTo (_arr: KeyValuePair<'TKey,'TValue> [], _arrayIndex: int) : unit = raise (System.NotImplementedException())
81+ member _.Keys : IEnumerable<'TKey> = raise (System.NotImplementedException())
82+ member _.Remove (_key: 'TKey) : bool = raise (System.NotImplementedException())
83+ member _.Remove (_item: KeyValuePair<'TKey,'TValue>) : bool = raise (System.NotImplementedException())
84+ *)
0 commit comments