Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 2.65 KB

README.md

File metadata and controls

76 lines (50 loc) · 2.65 KB

Logo

Dicts

Dicts on nuget.org Build Status Docs Build Status Test Status license code size

This F# library provides:

  • A dedicated Dict<'T> type. It is a thin wrapper around Dictionary<'T> with more functionality and nicer Error messages.

  • A DefaultDict<'T> type. It works like Python's' defaultdict.
    By providing a default function in the constructor it will always return a value for any key.

  • Extension methods for working with the IDictionary<'T> interface.

It also works in JS and TS with Fable.

This library was designed for use with F# scripting. Functions and methods never return null. Only functions starting with try... will return an F# Option. Otherwise when a function fails on invalid input it will throw a descriptive exception.

I was always annoyed that a KeyNotFoundExceptions does not include the actual bad key nor a pretty printed dictionary. This library fixes that in iDictionary.Get, iDictionary.Set and other item access functions.

Example

#r "nuget: Dicts"
open Dicts

let dd = DefaultDict<string,int>(fun _ -> ref 99)
incr dd.["A"]   // since dd.["A"] does not exist it will be created with the default value 99, and then incremented  to 100
incr dd.["A"]   // now it exists and will be incremented to 101
dd.["A"].Value  = 101 // true

Full API Documentation

goswinr.github.io/Dicts

Tests

All Tests run in both javascript and dotnet. Successful Fable compilation to typescript is verified too. Go to the tests folder:

cd Tests

For testing with .NET using Expecto:

dotnet run

for JS testing with Fable.Mocha and TS verification:

npm test

License

MIT

Changelog

see CHANGELOG.md