From af7f29f84b1dd6ece5c3e4db34665c7acb31fd58 Mon Sep 17 00:00:00 2001 From: BENJAMIN PEINHARDT Date: Wed, 28 Feb 2024 21:27:44 -0600 Subject: [PATCH] type signatures --- src/supervisors.gleam | 10 +++------- src/supervisors/a_shit_actor.gleam | 6 ++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/supervisors.gleam b/src/supervisors.gleam index b64119a..48653b4 100644 --- a/src/supervisors.gleam +++ b/src/supervisors.gleam @@ -73,13 +73,9 @@ pub fn main() { // with which to intialize itself. // There's a `supervisor.start_spec` function as well for tuning the // restart frequency and the initial state to pass to children. - let children = fn(children) { - children - |> supervisor.add(game) - } // We start the supervisor - let assert Ok(_supervisor_subject) = supervisor.start(children) + let assert Ok(_supervisor_subject) = supervisor.start(supervisor.add(_, game)) // The actor's init function sent us a subject for us to be able // to send it messages @@ -95,13 +91,13 @@ fn play_game( parent_subject: Subject(Subject(duckduckgoose.Message)), game_subject: Subject(duckduckgoose.Message), times n: Int, -) { +) -> Nil { case n { // Base Case, recess is over 0 -> Nil _ -> { case duckduckgoose.play_game(game_subject) { - // We're just a noraml old duck, so we keep playing + // We're just a normal old duck, so we keep playing Ok(msg) -> { io.println(msg) play_game(parent_subject, game_subject, n - 1) diff --git a/src/supervisors/a_shit_actor.gleam b/src/supervisors/a_shit_actor.gleam index f3d0c07..4f901c3 100644 --- a/src/supervisors/a_shit_actor.gleam +++ b/src/supervisors/a_shit_actor.gleam @@ -76,14 +76,16 @@ pub fn start( /// We provide this function in case we want to manually stop the actor, /// but in reality the supervisor will handle that for us. -pub fn shutdown(subject: Subject(Message)) { +pub fn shutdown(subject: Subject(Message)) -> Nil { actor.send(subject, Shutdown) } /// This is how we play the game. /// We are at the whim of the child as to whether we are a /// humble duck or the mighty goose. -pub fn play_game(subject: Subject(Message)) { +pub fn play_game( + subject: Subject(Message), +) -> Result(String, process.CallError(String)) { let msg_generator = random.weighted(#(9.0, Duck), [#(1.0, Goose)]) let msg = random.random_sample(msg_generator)