m8s
Joined 5 years ago
Joined 5 years ago
To me, Gleam feels like if Elm’s type system met Rust’s syntax. I really like it. But I also really liked Elixir too, I just can’t live without Gleam’s type system anymore.
Elixir’s use: https://hexdocs.pm/elixir/main/alias-require-and-import.html...
Gleam’s use: https://tour.gleam.run/advanced-features/use/
I find that `use` is quite effective when needed. This is the part referenced in her article where I find `use` particularly helpful. Something like:
fn outer() -> Result(success, failure) {
result.map(parse_id(), fn(id) {
... // More code that uses the id
})
}
Becomes: fn outer() -> Result(success, failure) {
use id <- result.map(parse_id())
... // More code that uses the id
}
In more concrete terms, I’m building an application with Gleam and Wisp that uses Wisp’s `require_form`. The type signature for `require_form` is: pub fn require_form(
request: Request(Connection),
next: fn(FormData) -> Response(Body),
) -> Response(Body)
But I get to use it like this: use form <- wisp.require_form(req)
I’m not sure if I have the appropriate nomenclature here, and I consider myself a beginner of writing strongly typed functional languages, but when I use `use`, I get to invoke the callback with the value on the left side of the arrow.As Erika so thoughtfully put it:
> The key is to use `use` when it allows you to highlight the happy path of your code … A use expression is syntax sugar, and it’s always possible to write Gleam code without it, though maybe not as clearly.
You can see more here [1] if you want, but note that there are a lot of structural changes in this codebase while I learn and figure out how to best use Gleam and Wisp :)
1. https://github.com/usepriceflow/app/blob/main/src/app/web/ad...