Skip to content

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

Open
@3willows

Description

@3willows

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions