aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/maybe.lux
blob: dabdcde5e295b0ab310f30694ea8e347de899e72 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(.module:
  [library
   [lux (#- if loop)
    ["$" documentation (#+ documentation:)]
    [data
     [text (#+ \n)
      ["%" format (#+ format)]]]
    [macro
     ["." template]]]]
  [\\library
   ["." /]])

(documentation: /.lifted
  "Wraps a monadic value with Maybe machinery."
  [(lifted monad)])

(documentation: /.else
  (format "Allows you to provide a default value that will be used"
          \n "if a (Maybe x) value turns out to be #.None."
          \n "Note: the expression for the default value will not be computed if the base computation succeeds.")
  [(else +20 (#.Some +10))
   "=>"
   +10]
  [(else +20 #.None)
   "=>"
   +20])

(documentation: /.trusted
  (format "Assumes that a Maybe value is a #.Some and yields its value."
          \n "Raises/throws a runtime error otherwise."
          \n "WARNING: Use with caution.")
  [(trusted trusted_computation)])

(documentation: /.when
  "Can be used as a guard in (co)monadic be/do expressions."
  [(do monad
     [value (do_something 1 2 3)
      /.when (passes_test? value)]
     (do_something_else 4 5 6))])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..lifted
             ..else
             ..trusted
             ..when
             ($.default /.monoid)
             ($.default /.functor)
             ($.default /.apply)
             ($.default /.monad)
             ($.default /.equivalence)
             ($.default /.hash)
             ($.default /.with)
             ($.default /.list)]
            []))