Skip to content

Commit 100e8b9

Browse files
committed
readme
1 parent 55e330b commit 100e8b9

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ ts/
1111
# FSharp.Formatting
1212
.fsdocs/
1313
output/
14-
tmp/
14+
tmp/
15+
16+
# will be generated by after build action:
17+
Docs/index.md

Docs/content/fsdocs-theme.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
code>span>span {
2+
color: rgb(133, 133, 133);
3+
/* font-weight: bold; */
4+
};
5+

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@
99
[![license](https://img.shields.io/github/license/goswinr/Dicts)](LICENSE.md)
1010
![code size](https://img.shields.io/github/languages/code-size/goswinr/Dicts.svg)
1111

12+
1213
This F# library provides:
14+
1315
- A dedicated `Dict<'T>` type. It is a thin wrapper around `Dictionary<'T>` with more functionality and nicer Error messages.
14-
- A `DefaultDict<'T>` type. It works like [Python's' defaultdict](https://docs.python.org/3/library/collections.html#collections.defaultdict).\
16+
17+
- A `DefaultDict<'T>` type. It works like [Python's' defaultdict](https://docs.python.org/3/library/collections.html#collections.defaultdict).<br>
1518
By providing a default function in the constructor it will always return a value for any key.
19+
1620
- Extension methods for working with the `IDictionary<'T>` interface.
1721

22+
It also works in JS and TS with [Fable](https://fable.io/).
23+
24+
This library was designed for use with F# scripting.
25+
Functions and methods never return null.
26+
Only functions starting with `try...` will return an F# Option.
27+
Otherwise when a function fails on invalid input it will throw a descriptive exception.
28+
29+
I was always annoyed that a KeyNotFoundExceptions does not include the actual bad key nor a pretty printed dictionary.
30+
This library fixes that in `iDictionary.Get`, `iDictionary.Set` and other item access functions.
1831

1932
### Example
2033

Src/DefaultDict.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type DefaultDict<'K,'V when 'K:equality > private (defaultOfKeyFun: 'K -> 'V, ba
126126
toString baseDic k v
127127

128128
/// A string representation of the DefaultDict including the count of entries and the first 5 entries.
129+
/// When used in Fable this member is inlined for reflection to work.
129130
#if FABLE_COMPILER
130131
member inline _.AsString = // inline needed for Fable reflection
131132
#else
@@ -144,6 +145,7 @@ type DefaultDict<'K,'V when 'K:equality > private (defaultOfKeyFun: 'K -> 'V, ba
144145

145146
/// A string representation of the DefaultDict including the count of entries
146147
/// and the specified amount of entries.
148+
/// When used in Fable this member is inlined for reflection to work.
147149
#if FABLE_COMPILER
148150
member inline _.ToString(entriesToPrint) = // inline needed for Fable reflection
149151
#else

Src/Dict.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ type Dict<'K,'V when 'K:equality > private (dic : Dictionary<'K,'V>) =
201201

202202

203203
/// A string representation of the Dict including the count of entries and the first 5 entries.
204+
/// When used in Fable this member is inlined for reflection to work.
204205
#if FABLE_COMPILER
205206
member inline _.AsString = // inline needed for Fable reflection
206207
#else
@@ -219,6 +220,7 @@ type Dict<'K,'V when 'K:equality > private (dic : Dictionary<'K,'V>) =
219220

220221
/// A string representation of the Dict including the count of entries
221222
/// and the specified amount of entries.
223+
/// /// When used in Fable this member is inlined for reflection to work.
222224
#if FABLE_COMPILER
223225
member inline _.ToString(entriesToPrint) = // inline needed for Fable reflection
224226
#else

Src/Dicts.fsproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@
6969
<Compile Include="Dict.fs" />
7070
<Compile Include="DefaultDict.fs" />
7171
</ItemGroup>
72+
73+
<Target Name="CopyReadmeToDocs" AfterTargets="Build">
74+
<!-- for fsdocs to build locally -->
75+
<Copy SourceFiles="../README.md" DestinationFiles="../Docs/index.md" ContinueOnError="false"/>
76+
</Target>
77+
7278
</Project>

Src/IDictionary.fs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ module ExtensionsIDictionary =
8484

8585

8686
/// A string representation of the IDictionary including the count of entries and the first 5 entries.
87-
member inline this.AsString = // inline needed for Fable
87+
#if FABLE_COMPILER
88+
member inline this.AsString = // inline needed for Fable reflection
89+
#else
90+
member this.AsString = // on .NET inline fails because it's using internal DefaultDictUtil
91+
#endif
8892
let b = Text.StringBuilder()
8993
let c = this.Count
9094
b.Append(toString this) |> ignore
@@ -97,7 +101,11 @@ module ExtensionsIDictionary =
97101

98102
/// A string representation of the IDictionary including the count of entries
99103
/// and the specified amount of entries.
100-
member inline this.ToString(entriesToPrint) = // inline needed for Fable
104+
#if FABLE_COMPILER
105+
member inline this.ToString(entriesToPrint) = // inline needed for Fable reflection
106+
#else
107+
member this.ToString(entriesToPrint) = // on .NET inline fails because it's using internal DefaultDictUtil
108+
#endif
101109
let b = Text.StringBuilder()
102110
let c = this.Count
103111
b.Append(toString this) |> ignore

0 commit comments

Comments
 (0)