Skip to content
#

stdlib

Here are 140 public repositories matching this topic...

edkelly303
edkelly303 commented Nov 10, 2020

Elm has a function called clamp in its standard library, which I have often found quite useful to restrict a number within an upper and lower bound. We could implement it in Gleam something like this:

pub fn clamp(x: Int, bound1: Int, bound2: Int) -> Int {
  let lower_bound = min(bound1, bound2)
  let upper_bound = max(bound1, bound2)
  x
  |> min(upper_bound)
  |> max(lower_bo

Improve this page

Add a description, image, and links to the stdlib topic page so that developers can more easily learn about it.

Curate this topic

Add this topic to your repo

To associate your repository with the stdlib topic, visit your repo's landing page and select "manage topics."

Learn more

You can’t perform that action at this time.