Conversation
b1e3f8a to
a393b13
Compare
lpil
left a comment
There was a problem hiding this comment.
Thank you! Sorry for taking so long, you've been at the end of the inbox for far too long and I'm only just getting through all the notifications
| * @param {string} str String passed to quux | ||
| * @returns {string} An unprocessed string | ||
| */ | ||
| function quux(string) { return str; } |
There was a problem hiding this comment.
Could you remove all the foobar references please
|
|
||
| #### Gleam | ||
|
|
||
| Gleam's functions are declared using a syntax similar to Rust. Gleam's anonymous |
| } | ||
|
|
||
| let mul = fn(x, y) { x * y } | ||
| mul(1, 2) |
There was a problem hiding this comment.
This code implies you can have top level expressions as if Gleam were a scripting language, but this is not the case
There was a problem hiding this comment.
Although it's on the gleam tour already, I think it's worth repeating there is no explicit return, because many JS developers might not know other functional language.
|
|
||
| let add2 = fn(x) { add(x, 2) } | ||
| // is equivalent to: | ||
| let add2 = add(_, 2) |
| } | ||
| ``` | ||
|
|
||
| ### Referencing functions |
There was a problem hiding this comment.
I think we can remove this section as JS programmers wouldn't expect anything else
| ### Notes on operators | ||
|
|
||
| - JavaScript operators are short-circuiting as in Gleam. | ||
| - Gleam's `/` operator always returns an integer. |
There was a problem hiding this comment.
| - Gleam's `/` operator always returns an integer. | |
| - Gleam's `/` operator always returns an int. |
| ### Tuples | ||
|
|
||
| Tuples are very useful in Gleam as they're the only collection data type that | ||
| allows mixed types in the collection. |
|
|
||
| #### Gleam | ||
|
|
||
| Gleam has a "cons" operator that works for lists destructuring and pattern |
There was a problem hiding this comment.
We don't have a cons operator, we have a list-prepend syntax
| import gleam/dict | ||
|
|
||
| dict.from_list([#("key1", "value1"), #("key2", "value2")]) | ||
| dict.from_list([#("key1", "value1"), #("key2", 2)]) // Type error! |
| "hello, world" | ||
| |> string.uppercase | ||
| |> string.repeat(2) // defaults to piping into the first argument | ||
| |> string.split(_, ",") // you can use _ to specify the argument to pipe into |
There was a problem hiding this comment.
Would be good to pipe into the second position as the first is the default
#414
I started adapting the Elixir cheatsheet for JavaScript/TypeScript. Still far from perfect, but it might be ready for a review 🤞