Snippets tagged generics

  • Create generic IEnumerable from non-generic

    Depends on Castle Dynamic Proxy 2. Returns an IEnumerable from a System.Type and a System.Collections.IEnumerable. It is a hack I wrote simply because I couldn't find anything in the framework to do this.

    25 people like this

    Posted: 6 years ago by Dan Finch

  • .NET 1.1 collections in F#

    Even with the latest tools, we're sometimes exposed to .NET archeaology: parts of the framework designed before .NET 2. Examples of this are the dictionary classes from System.Collections, which are a little strongly typed, but not quite -- you see them if you call HttpUtility.ParseQueryString, or if you use pretty much anything in System.Configuration. Here's some code to make these classes a little safer in F#.

    3 people like this

    Posted: 4 years ago by Tim Robinson

  • Generic Numeric Type Conversions

    Function that converts numeric types using type inference. This is meant to complement the generic number literal G in helping to write generic numeric code. The implementation is similar to the generic number literal snippet. See http://fssnip.net/mv/

    1 people like this

    Posted: 2 years ago by Sami Perttu

  • Apply Operators to Options

    Simple function to apply operators to option types. Applies the operator to each value and returns a new option containing the result. Treats None as the operator's identity element (i.e., ignores it).

    1 people like this

    Posted: 5 years ago by Richard Broida

  • Generic number literal

    A generic numeral G. It allows writing functions for arbitrary numeric type. The transformation is an efficient one, because it is implemented explicitly for every type. It combines the type classes technique of FsControl (https://github.com/gmpl/FsControl and http://nut-cracker.azurewebsites.net/typeclasses-for-fsharp) with numeric literals. But FsControl is removed to completely avoid unnecessary function calls.

    4 people like this

    Posted: 3 years ago by Daniel Fabian (@iceypoi)