Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case expressions: refactor examples involving random input to permit easy variation of results #130

Open
3willows opened this issue Oct 11, 2024 · 1 comment

Comments

@3willows
Copy link

3willows commented Oct 11, 2024

Hi!

I am totally new to the language, just started playing with the playground after hearing about Gleam from a Red Badger meet-up.

As I was mucking around, I made light changes to the examples involving random inputs as follows (e.g. this), which allows me to see different cases being triggered in the output.

import gleam/int
import gleam/io

pub fn main() {
  example()
  example()
  example()
}

fn example() {
  let x = int.random(5)
  io.debug(x)

  let result = case x {
    // Match specific values
    0 -> "Zero"
    1 -> "One"

    // Match any other value
    _ -> "Other"
  }
  io.debug(result)
}

Just wonder whether this is an ever slightly easier example for absolute beginners to work through.

@lpil
Copy link
Member

lpil commented Oct 11, 2024

Hello! Sounds like a nice idea to me. Or perhaps randomness could be abandoned and a few different values could be passed in.

Great to hear the Badgers are chatting about Gleam. I've a lot of time for Stu and the gang, they're a great bunch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants