-
Notifications
You must be signed in to change notification settings - Fork 2
Home
InCube released its Core libraries for C# as open source on Github and in binary form on nuget.org. With the arrival of .Net Core, the ecosystem of high quality open source libraries for C# has experienced a very strong growth. We would like to contribute to this positive evolution by making our Core libraries available to the .Net community.
At InCube we believe that concepts from functional programming aid in developing robust and maintainable code. A couple of years ago, F# used to be the primary programming language in our projects. With the arrival of more functional paradigms in C# 7 and extensions like LINQ, we switched to C# as our new choice for backend development. However, we found that the .NET Standard library was missing some generally useful functional datatypes. Our C# Core library provides implementations of various such types, which we have ported from either F# or Scala and adjusted to C# API standards.
One the most prominent functional data types that is currently missing in C# is the Option type. The next compiler release, C# 8, attempts to close this gap by introducing nullable reference types. The designers of C# chose to address this problem by means of syntax extensions and static code analysis. The concepts behind this design are extremely powerful, but their implementation in Roslyn poses some serious challenges. Moreover, using these extensions in existing code bases might become tedious since it requires opting into non-backwards compatible compiler features via pragma directives.
Until nullable reference types reach an acceptable level of maturity, InCube's Core library offers the data types Option<T>
and Maybe<T>
. It builds on the stable release of .NET Standard, has very lean dependencies, and promises seamless, non-intrusive integration with existing code bases. Option<T>
has been designed along the lines of Nullable<T>
, but works with any underlying type T
, not only struct
types. Option<T>
and Nullable<T>
share essentially the same programming interface. Maybe<T>
is a performance optimization of Option<T>
when T
is known to be a class
type. The usage of Option<T>
is demonstrated in the User Guide and in OptionDemo
.
The library also offers some more advanced functional data types. The Either<TL, T>
type represents the union of two data types TL
and T
. A Try<T>
is the functional equivalent of a try-catch block, that is, it holds either a valid result of some computation or an Exception
. For instance, one can emulate checked exceptions in C# by using Try<T>
for the return type of a function. Moreover, the library provides convenient extension methods for Nullable<T>
which create a more natural integration with concepts from LINQ and Option<T>
.
Lastly, InCube Core contains various extension methods for Enumerables, Lists, Dictionaries, and Tuples. An overview is given in the project README. In addition, the library provides some numerical helpers, e.g., for computing histograms and ranks. There are also utilities for implementing Preconditions and managing large collections of disposable objects in a single IDisposable
.
We are curious to hear your feedback. Please contact us at InCube or submit a ticket if you have any suggestions for improvement.