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: 13 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: 10 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: 8 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: 11 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: 9 years ago by Daniel Fabian (@iceypoi)

  • Dynamic Invocation of Generic Functions In A Module

    A quick snippet showing three different ways of dynamically/reflectively locating a module then invoking a generic function. The first two don't rely on a class. But the third is more readable/understandable for most .NET devs.

    5 people like this

    Posted: 3 years ago by Cerberus (FSharp Discord)