Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FSharpCSharpInteroperability
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) =>
FSharpAsync.StartAsTask(
computation,
new FSharpOption<TaskCreationOptions>(TaskCreationOptions.None),
new FSharpOption<CancellationToken>(CancellationToken.None));
}
}
namespace FSharpCSharpInteroperability
open System.Runtime.CompilerServices
open System.Threading.Tasks
[<Extension>]
type public FSharpFuncUtil =
[<Extension>]
static member ToFSharpFunc (func:System.Func<Task<'a>>) = fun () -> func.Invoke() |> Async.AwaitTask
[<Extension>]
static member ToFSharpFunc (func:System.Func<'b, Task<'a>>) = fun (b) -> func.Invoke(b) |> Async.AwaitTask
[<Extension>]
static member ToFSharpFunc (func:System.Func<'a>) = fun() -> func.Invoke();
[<Extension>]
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
You can’t perform that action at this time.