Skip to content

Instantly share code, notes, and snippets.

View mikhailshilkov's full-sized avatar

Mikhail Shilkov mikhailshilkov

View GitHub Profile
[FunctionName("SequentialWorkflow")]
public static async Task Sequential([OrchestrationTrigger] DurableOrchestrationContext context)
{
var conference = await context.CallActivityAsync<ConfTicket>("BookConference", "ServerlessDays");
var flight = await context.CallActivityAsync<FlightTickets>("BookFlight", conference.Dates);
await context.CallActivityAsync("BookHotel", flight.Dates);
}
[FunctionName("BookConference")]
public static ConfTicket BookConference([ActivityTrigger] string conference)
{
var ticket = BookingService.Book(conference);
return new ConfTicket { Code = ticket };
}
[FunctionName("MyFirstFunction")]
public static void QueueTrigger(
[QueueTrigger("myqueue-items")] string myQueueItem,
ILogger log)
{
log.LogInformation($"C# function processed: {myQueueItem}");
}
// Given
Monad<T> monadicValue;
// Then (== means both parts are equivalent)
monadicValue.Bind(x => new Monad<T>(x)) == monadicValue
// Given
Monad<T> m;
Func<T, Monad<U>> f;
Func<U, Monad<V>> g;
// Then (== means both parts are equivalent)
m.Bind(f).Bind(g) == m.Bind(a => f(a).Bind(g))
// Given
T value;
Func<T, Monad<U>> f;
// Then (== means both parts are equivalent)
new Monad<T>(value).Bind(f) == f(value)
let loop () = actor {
let! message = mailbox.Receive()
match message with
| Greet(name) -> printfn "Hello %s" name
| Hi -> printfn "Hello from F#!"
return! loop ()
}
type MaybeBuilder() =
member this.Bind(x, f) =
match x with
| None -> None
| Some a -> f a
member this.Return(x) =
Some x
let nextTalkCity (speaker: Speaker) = maybe {
let! talk = speaker.nextTalk()
let! conf = talk.getConference()
let! city = conf.getCity(talk)
return city
}
let sendReservation () = async {
let! speaker = repository.LoadSpeaker()
let! talk = speaker.nextTalk()
let! conf = talk.getConference()
let! city = conf.getCity()
do! bookFlight(speaker, city)
}