aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter5_advanced_features/lesson01_use/en.html
blob: d879aecb19a709d1464f89aaa2a8ee67163f63de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<p>
  Gleam lacks exceptions, macros, type classes, early returns, and a variety of
  other features, instead going all-in with just first-class-functions and
  pattern matching. This makes Gleam code easier to understand, but it can
  sometimes result in excessive indentation.
</p>
<p>
  Gleam's use expression helps out here by enabling us to write code that uses
  callbacks in an unindented style, as shown in the code window.
</p>

<p>
  The higher order function being called goes on the right hand side of the
  <code>&lt;-</code> operator. It must take a callback function as its final
  argument.
</p>
<p>
  The argument names for the callback function go on the left hand side of the
  <code>&lt;-</code> operator. The function can take any number of arguments,
  including zero.
</p>
<p>
  All the remaining code in the enclosing <code class="hljs">{}</code> block
  becomes the body of the callback function.
</p>
<p>
  This is a very capable and useful feature, but excessive application of
  <code>use</code> may result in unclear code, especially to beginners. Usually
  the regular function call syntax results in more approachable code!
</p>