#What might be the reason this code doesn't finish?

1 messages · Page 1 of 1 (latest)

errant valve
#

I am doing https://exercism.org/tracks/gleam/exercises/newsletter

Somehow, "- log" is never printed:

pub fn send_newsletter(
  emails_path: String,
  log_path: String,
  send_email: fn(String) -> Result(Nil, Nil),
) -> Result(Nil, Nil) {
  io.debug("+ log")
  let _logs =
    result.map(read_emails(emails_path), fn(emails) {
      list.map(emails, fn(email) {
        result.then(send_email(email), fn(_) { log_sent_email(log_path, email) })
      })
    })
  io.debug("- log")
  Ok(Nil)
}

What might be the reason for that?

I believe there is no error thrown, is there?

*sorry for a beginner question, just started writing Gleam last week 😄

Exercism

Can you solve Newsletter in Gleam? Improve your Gleam skills with support from our world-class team of mentors.

echo portal
#

Are you running on exercism?

#

The website

errant valve
#

no, I am running on VSCode

#

And when I uncomment the let _logs block, the - log will be printed

echo portal
#

And the test passes?

errant valve
#

Failed

"+ log"
F
test/newsletter_test.gleam
   test: send_newsletter_test
  error: Pattern match failed
   site: newsletter_test:58
  value: Error(Enoent)
...
Ran 4 tests, 1 failed
#

Oh I see, it is stopped due to failed assertion here then 👍

echo portal
#

Phew mystery solved

#

I thought something weird was happening

errant valve
#

Haha, thx!

I initially thought some statements are lazily evaluated

echo portal
#

Ah I see