Flavedo.Zest 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Flavedo.Zest --version 0.0.1
NuGet\Install-Package Flavedo.Zest -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Flavedo.Zest" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flavedo.Zest --version 0.0.1
#r "nuget: Flavedo.Zest, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Flavedo.Zest as a Cake Addin
#addin nuget:?package=Flavedo.Zest&version=0.0.1

// Install Flavedo.Zest as a Cake Tool
#tool nuget:?package=Flavedo.Zest&version=0.0.1

Flavedo.Zest

Task module

TaskC# での await をサポートするための関数を提供しています。 また、System.Threading.Tasks.Taskクラス の一部のメソッドにも対応しています。

Task.await

非同期処理を同期処理のように記述することが可能です。
これは C#await と対応しています。

// C#
using System;
using System.IO;
using System.Threading.Tasks;

namespace Sample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var path = "./sample.txt";
            using var reader = new StreamReader(path);
            var content = await reader.ReadToEndAsync();
        }
    }
}
// F#
open Flavedo.Zest
open System.IO

[<Literal>]
let path = "./sample.txt"
let reader = new StreamReader(path)
let content = Task.await (reader.ReadToEndAsync())

また、複数の非同期タスクを待機する場合は以下のように記述可能です。

// F#
open Flavedo.Zest
open System.IO

[<Literal>]
let path1 = "./sample1.txt"
[<Literal>]
let path2 = "./sample2.txt"
let reader1 = new StreamReader(path1)
let reader2 = new StreamReader(path2)

// 方法1
let task1 = reader1.ReadToEndAsync()
let task2 = reader2.ReadToEndAsync()
let (content1, content2) = Task.await (task1, task2)
// 方法2
let (content1, content2) = Task.await (reader1.ReadToEndAsync(), reader2.ReadToEndAsync())

Task.run

同期的処理を非同期処理として実行することが可能です。
これは C#Task.Run() と対応しています。

// C#
using System;
using System.Threading.Tasks;

namespace Sample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            await Task.Run(() =>
            {
                for (var i = 0; i < 10; i++)
                    Console.WriteLine($"i = {i}");
            });
        }
    }
}
// F#
open Flavedo.Zest

Task.await (Task.run(fun () ->
    for i in 0..9 do
        printfn "i = %d" i ))

また、戻り値がある関数にも対応しています。

// C#
using System;
using System.Threading.Tasks;

namespace Sample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var result = await Task.Run(() =>
            {
                // do something
                return "result";
            });
        }
    }
}
// F#
open Flavedo.Zest

let result = Task.await (Task.run(fun () ->
    // do something
    "result" ))

Task.delay

処理を一定時間遅延させたい場合に利用します。
これは C#Task.Delay() と対応しています。

// C#
using System;
using System.Threading.Tasks;

namespace Sample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            await Task.Delay(1_000); // 1秒遅延
            Console.WriteLine("Hello, World!!");
        }
    }
}
// F#
open Flavedo.Zest

Task.await (Task.delay(1_000<millisec>)) // 1秒遅延
printfn "Hello, World!!"
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2.1 347 2/14/2021
0.0.2 461 9/14/2020
0.0.1 499 9/12/2020