Dumping ground for multi-paradigm programming ideas in C#.
Below is a summary of what this repo contains. Note that not everything in this library is meant to be taken completely seriously. Some facilities are almost sarcastic in their inclusion.
Unit- has only one meaningully unique valueVoid- no value can be constructed; is always nullMaybe<A>- may or may not have a value and maps functions over missing valueEither<A, B>- represents a distinction between two possible types of valuesNewType<A>- wraps existing types to distinguish on the type levelMonoid<A>- appends values of a particular type into combined values of the same typeFunctor<FA, FB, A, B>- lifts a functionA => Binto the space ofF
ListOf,SeqOf,DictOf- concise collection creation:DictOf("one", 1, "two", 2, "three", 3)Cmp- sets up expressive bound comparisons:0 <= Cmp(x) < 10Eq,Same,Str,Hash- null-safe basic object operationsApply- partially apply functionsSplit- splits strings byRegexA.IsIn(IEnumerable<A>),A.IsIn(params A[])- reversed contains checkIEnumerable.AsStream,Stream.AsEnumerable- convertsIEnumerables to/fromStreamsBatch- split sequence into subsequences of consecutive valuesBuffer- eagerly evaluate sequence ahead of time in arbitrary sized groupsCrossJoin- zip every element in sequence with every element in another sequenceCycle- repeat elements of a sequence infinitelyDeal- split sequence into subsequences of every nth valueFlatten- combine values of subsequences into one long sequenceForever- create lazy sequence by repeatedly calling an impure functionInterleave- create a sequence of the values of multiple sequences round-robinIntersperse- create a sequence of elements from one sequence with all the elements of another between each oneOverlappingPairs- creates a sequence of tuple pairs of overlapping adjacent pairs in a sequenceShuffle- randomize ordering of a sequenceZipExact- zip two sequences, raising an error if one runs out before the other
AsyncQueue<A>- asynchronous queue that allows awaiting on value inserted into empty queueBankersQueue<A>- persistent queue made from twoConsListsBitmappedTrie<A>- persistent vector with tree structureComputedList<A>- list that generates values based on index instead of storing in memoryConsList<A>- an immutable, singly-linked listDefaultingDictionary<A, Z>- dictionary that defers to another dictionary when key is missingDictionary<A, B, Z>-Dictionarys that useTuplefor aggregate keysFingerTree<A>- a persistent dequeue implemented as 2,3-finger treePairingHeap<A>- a self-balancing, persistent, ordered heapRadixDictionary<A>- mutable dictionary optimized for string keysRoseTree<A>- mutable tree data structure that braches arbitrarily
Factorial- factorial as an extension method onintPermutationCount- computes number of permutations for given collection size and subsequence sizePermutations- creates sequence of permutations of given sizeAllPermutations- creates sequence of permutations of all sizesCombinationCount- computes number of combinations for given collection size and subset sizeCombinations- creates sequence of combinations of elements of given sizeAllCombinations- creates sequence of combinations of all sizes
IFileSystem- interface representing minimal set of file system operationsRealFileSystem- forwards operations toSystem.IOclassesVirtualFileSystem- in-memory file system data structureResilientFileSystem-IFileSystemdecorator that adds retry logic to all operations
MultiMethod- group of functions that execute based on argument type or arbitrary predicate
Atom<A>- mutually exclusive reference cell with synchronous updates that is both divisible and composableLock- exclusive locking primitive built onMonitor.Enter/.Exitthat is composible
Cond- builds a list of clauses and conditionally evaluates consequentsCase- likeCond, but clauses are applied to a key value
Retry.Exponential- waits double time between each successive attempt of an operationRetry.Fractal- subdivides workload of batch operations, retrying as series of smaller batchesRetry.Sequential- attempts a series of alternate arguments to parameterized operation
Batcher- accumulates arguments toPushmethod until limit is reached orFlushis calledCache- uses code generation to build wrapper class around interface implementation that caches all methodsDebounce- returns new version of an action that only passes through call after a time has passed since last callMemo- returns new version of a function that caches return value for inputs, with optional expiration timeSprinkler- splits items from batches passed toPushspread out by time delay
Scope.Push,Scope.Get- controlled, thread local, global variables that are only defined farther down the call chain
Needs- a minimal-configuration IoC container that can search assemblies and parent types and failover to other IoC containersSingleUse- an attribute indicating that a dependency implementation is not threadsafe or can only be used once
DateSpan- region of time between two dates
Expect- testing for exceptions and property based testing; companion to AssertRand- produces random test dataSample- provides common and edge-case test valuesAll- enumerates all values of certain types
Io- a type for modeling and composing I/O operations and side effectsLens- composable get and set pair for immutable types
- Looks weird
- But looks cool
- Uses overloaded
/operator to build paths - Works on .Net/Windows and Mono/Linux
Drive.C / "Folder1" / "Folder2" / "File.txt"
"C:\\Folder1\\Folder2\\File.txt" (Windows)
Folder.AppData / "MyApp" / "Config.xml"
"C:\\Users\\Me\\AppData\\MyApp\\Config.xml" (Windows)
"/users/me/.config/MyApp/Config.xml" (Linux)- This was clearly a mistake
- I am so sorry
- Uses overloaded
<,>,<=and>=operators to build XML - Lets you do this:
Xml.Doc < "catalog"
< "book" >= "id" <= "bk101"
< "author" <= "Gambardella, Matthew"
< "title" <= "XML Developer's Guide"
< "price" >= "currency" <= "USD" <= "44.95" > Xml.End
< "book" >= "id" <= "bk102"
< "author" <= "Ralls, Kim"
< "title" <= "Midnight Rain"
< "price" >= "currency" <= "USD" <= "5.95" > Xml.EndDocwhich generates
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price currency="USD">44.95</price>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price currency="USD">5.95</price>
</book>
</catalog>