Skip to content

Instantly share code, notes, and snippets.

@zelid
Created August 21, 2020 17:17
Show Gist options
  • Save zelid/fdf5e53544f9c979e91b492bdaf01aae to your computer and use it in GitHub Desktop.
Save zelid/fdf5e53544f9c979e91b492bdaf01aae to your computer and use it in GitHub Desktop.
Async F# Question
namespace fsharp
open System
open System.Collections.Generic
open System.IO
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open ServiceStack // <----- try comment this and `async {` will not be errored by compiller
module AsyncDemo =
type Student = {
name: string
age: int
subjects: string []
}
type IStudentApi =
{ allStudents : Async<Student list>
findByName : string -> Async<Student option> }
let students() = [
{ name = "Alice"; age = 20; subjects = [| "math" |] }
{ name = "Martin"; age = 19; subjects = [| "cs" |] }
]
let studentApi : IStudentApi = {
allStudents = async { return students() }
findByName = fun name -> async {
let foundStudent =
students()
|> List.tryFind (fun student -> student.name = name)
return foundStudent
}
}
module Program =
let exitCode = 0
let CreateHostBuilder args =
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(fun webBuilder ->
ModularExtensions.UseModularStartup<Startup>(webBuilder) |> ignore
)
[<EntryPoint>]
let main args =
CreateHostBuilder(args).Build().Run()
exitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment