FSharpCSharpInteroperability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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