Skip to content

Instantly share code, notes, and snippets.

@jhoerr
Last active January 3, 2017 01:40
Show Gist options
  • Save jhoerr/40ab58e230c614edc55d to your computer and use it in GitHub Desktop.
Save jhoerr/40ab58e230c614edc55d to your computer and use it in GitHub Desktop.
Bingo!
// lightbulb
public static async Task<TOut> MapAsync<TIn,TOut>(this Task<TIn> @this, Func<TIn, Task<TOut>> fn) => await fn(await @this);
// all permutations
public static TOut Map<TIn,TOut>(this TIn @this, Func<TIn, TOut> fn) => fn(@this);
public static async Task<TOut> MapAsync<TIn,TOut>(this TIn @this, Func<TIn, Task<TOut>> fn) => await fn(@this);
public static async Task<TOut> MapAsync<TIn,TOut>(this Task<TIn> @this, Func<TIn, TOut> fn) => fn(await @this);
public static async Task<TOut> MapAsync<TIn,TOut>(this Task<TIn> @this, Func<TIn, Task<TOut>> fn) => await fn(await @this);
// example
var x = 1;
var i = await x.Map(H).MapAsync(G).MapAsync(F); // i == 9
@Charmand3r
Copy link

Charmand3r commented Jan 3, 2017

Hi, im interested in using this, can you please tell me how to make it work on tampermonkey?
email me @ marineoverlord@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment