Skip to content

Instantly share code, notes, and snippets.

Last active June 18, 2020 13:21
What would you like to do?
namespace Api.CompositionRoot
using System.Threading;
using System.Threading.Tasks;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
public static class FSharpAsyncExtension
public static Task<T> StartAsDefaultTask<T>(this FSharpAsync<T> computation) =>
new FSharpOption<TaskCreationOptions>(TaskCreationOptions.None),
new FSharpOption<CancellationToken>(CancellationToken.None));
namespace FSharpCSharpInteroperability
open System.Runtime.CompilerServices
open System.Threading.Tasks
type public FSharpFuncUtil =
static member ToFSharpFunc (func:System.Func<Task<'a>>) = fun () -> func.Invoke() |> Async.AwaitTask
static member ToFSharpFunc (func:System.Func<'b, Task<'a>>) = fun (b) -> func.Invoke(b) |> Async.AwaitTask
static member ToFSharpFunc (func:System.Func<'a>) = fun() -> func.Invoke();
static member ToFSharpFunc<'a,'b> (func:System.Func<'a,'b>) = fun x -> func.Invoke(x)
module NullableOptionUtil
let ToOption (n: System.Nullable<_>) =
if n.HasValue then Some n.Value else None
let StringToOption(n: string) =
if System.String.IsNullOrEmpty(n) then None else Some n
let ToNullable (n: option<'a>) =
if n.IsSome then new System.Nullable<'a>(n.Value) else new System.Nullable<'a>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment