create-mendix-widget-gleam 2.0.14 → 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -1
  3. package/src/index.mjs +22 -7
  4. package/template/gleam.toml +1 -1
  5. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache +0 -0
  6. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache_inline +0 -0
  7. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache_meta +0 -0
  8. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache +0 -0
  9. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache_inline +0 -0
  10. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache_meta +0 -0
  11. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache +0 -0
  12. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache_inline +0 -0
  13. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache_meta +0 -0
  14. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache +0 -0
  15. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache_inline +0 -0
  16. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache_meta +0 -0
  17. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache +0 -0
  18. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache_inline +0 -0
  19. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache_meta +0 -0
  20. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache +0 -0
  21. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache_inline +0 -0
  22. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache_meta +0 -0
  23. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache +0 -0
  24. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache_inline +0 -0
  25. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache_meta +0 -0
  26. package/tui/build/dev/javascript/etch/etch/command.mjs +479 -0
  27. package/tui/build/dev/javascript/etch/etch/cursor.mjs +164 -0
  28. package/tui/build/dev/javascript/etch/etch/event.mjs +2399 -0
  29. package/tui/build/dev/javascript/etch/etch/internal/consts.mjs +3 -0
  30. package/tui/build/dev/javascript/etch/etch/stdout.mjs +375 -0
  31. package/tui/build/dev/javascript/etch/etch/style.mjs +741 -0
  32. package/tui/build/dev/javascript/etch/etch/terminal.mjs +137 -0
  33. package/tui/build/dev/javascript/etch/gleam.mjs +1 -0
  34. package/tui/build/dev/javascript/etch/input/event_ffi.erl +73 -0
  35. package/tui/build/dev/javascript/etch/input/input_ffi.mjs +192 -0
  36. package/tui/build/dev/javascript/etch/input/signal_handler.erl +33 -0
  37. package/tui/build/dev/javascript/etch/terminal/terminal_ffi.erl +22 -0
  38. package/tui/build/dev/javascript/etch/terminal/terminal_ffi.mjs +37 -0
  39. package/tui/build/dev/javascript/etch/terminal/tty_state.erl +29 -0
  40. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache +0 -0
  41. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache_inline +0 -0
  42. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache_meta +0 -0
  43. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache +0 -0
  44. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_inline +0 -0
  45. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_meta +0 -0
  46. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache +0 -0
  47. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_inline +0 -0
  48. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_meta +0 -0
  49. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache +0 -0
  50. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_inline +0 -0
  51. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_meta +0 -0
  52. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache +0 -0
  53. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache_inline +0 -0
  54. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache_meta +0 -0
  55. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache +0 -0
  56. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_inline +0 -0
  57. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_meta +0 -0
  58. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache +0 -0
  59. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache_inline +0 -0
  60. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache_meta +0 -0
  61. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/application.mjs +38 -0
  62. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/atom.mjs +2 -0
  63. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/charlist.mjs +1 -0
  64. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/node.mjs +12 -0
  65. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/port.mjs +1 -0
  66. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/process.mjs +161 -0
  67. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/reference.mjs +1 -0
  68. package/tui/build/dev/javascript/gleam_erlang/gleam.mjs +1 -0
  69. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@application.erl +43 -0
  70. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@atom.erl +94 -0
  71. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@charlist.erl +42 -0
  72. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@node.erl +80 -0
  73. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@port.erl +8 -0
  74. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@process.erl +868 -0
  75. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@reference.erl +21 -0
  76. package/tui/build/dev/javascript/gleam_erlang/gleam_erlang_ffi.erl +164 -0
  77. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache +0 -0
  78. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache_inline +0 -0
  79. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache_meta +0 -0
  80. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache +0 -0
  81. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache_inline +0 -0
  82. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache_meta +0 -0
  83. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache +0 -0
  84. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache_inline +0 -0
  85. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache_meta +0 -0
  86. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/array.mjs +24 -0
  87. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/promise.mjs +105 -0
  88. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/symbol.mjs +7 -0
  89. package/tui/build/dev/javascript/gleam_javascript/gleam.mjs +1 -0
  90. package/tui/build/dev/javascript/gleam_javascript/gleam_javascript_ffi.mjs +133 -0
  91. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache +0 -0
  92. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_inline +0 -0
  93. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta +0 -0
  94. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache +0 -0
  95. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_inline +0 -0
  96. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta +0 -0
  97. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache +0 -0
  98. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_inline +0 -0
  99. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_meta +0 -0
  100. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache +0 -0
  101. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_inline +0 -0
  102. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta +0 -0
  103. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache +0 -0
  104. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_inline +0 -0
  105. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta +0 -0
  106. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache +0 -0
  107. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_inline +0 -0
  108. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_meta +0 -0
  109. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache +0 -0
  110. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_inline +0 -0
  111. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta +0 -0
  112. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache +0 -0
  113. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_inline +0 -0
  114. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta +0 -0
  115. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache +0 -0
  116. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_inline +0 -0
  117. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta +0 -0
  118. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache +0 -0
  119. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_inline +0 -0
  120. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta +0 -0
  121. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache +0 -0
  122. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_inline +0 -0
  123. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta +0 -0
  124. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache +0 -0
  125. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_inline +0 -0
  126. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta +0 -0
  127. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache +0 -0
  128. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_inline +0 -0
  129. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta +0 -0
  130. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache +0 -0
  131. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_inline +0 -0
  132. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta +0 -0
  133. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache +0 -0
  134. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_inline +0 -0
  135. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta +0 -0
  136. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache +0 -0
  137. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_inline +0 -0
  138. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta +0 -0
  139. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache +0 -0
  140. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_inline +0 -0
  141. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta +0 -0
  142. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache +0 -0
  143. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_inline +0 -0
  144. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_meta +0 -0
  145. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache +0 -0
  146. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_inline +0 -0
  147. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta +0 -0
  148. package/tui/build/dev/javascript/gleam_stdlib/dict.mjs +710 -0
  149. package/tui/build/dev/javascript/gleam_stdlib/gleam/bit_array.mjs +286 -0
  150. package/tui/build/dev/javascript/gleam_stdlib/gleam/bool.mjs +295 -0
  151. package/tui/build/dev/javascript/gleam_stdlib/gleam/bytes_tree.mjs +225 -0
  152. package/tui/build/dev/javascript/gleam_stdlib/gleam/dict.mjs +455 -0
  153. package/tui/build/dev/javascript/gleam_stdlib/gleam/dynamic/decode.mjs +993 -0
  154. package/tui/build/dev/javascript/gleam_stdlib/gleam/dynamic.mjs +35 -0
  155. package/tui/build/dev/javascript/gleam_stdlib/gleam/float.mjs +528 -0
  156. package/tui/build/dev/javascript/gleam_stdlib/gleam/function.mjs +6 -0
  157. package/tui/build/dev/javascript/gleam_stdlib/gleam/int.mjs +764 -0
  158. package/tui/build/dev/javascript/gleam_stdlib/gleam/io.mjs +8 -0
  159. package/tui/build/dev/javascript/gleam_stdlib/gleam/list.mjs +3063 -0
  160. package/tui/build/dev/javascript/gleam_stdlib/gleam/option.mjs +386 -0
  161. package/tui/build/dev/javascript/gleam_stdlib/gleam/order.mjs +166 -0
  162. package/tui/build/dev/javascript/gleam_stdlib/gleam/pair.mjs +96 -0
  163. package/tui/build/dev/javascript/gleam_stdlib/gleam/result.mjs +448 -0
  164. package/tui/build/dev/javascript/gleam_stdlib/gleam/set.mjs +413 -0
  165. package/tui/build/dev/javascript/gleam_stdlib/gleam/string.mjs +695 -0
  166. package/tui/build/dev/javascript/gleam_stdlib/gleam/string_tree.mjs +128 -0
  167. package/tui/build/dev/javascript/gleam_stdlib/gleam/uri.mjs +1151 -0
  168. package/tui/build/dev/javascript/gleam_stdlib/gleam.mjs +1 -0
  169. package/tui/build/dev/javascript/gleam_stdlib/gleam@bit_array.erl +347 -0
  170. package/tui/build/dev/javascript/gleam_stdlib/gleam@bool.erl +334 -0
  171. package/tui/build/dev/javascript/gleam_stdlib/gleam@bytes_tree.erl +211 -0
  172. package/tui/build/dev/javascript/gleam_stdlib/gleam@dict.erl +513 -0
  173. package/tui/build/dev/javascript/gleam_stdlib/gleam@dynamic.erl +105 -0
  174. package/tui/build/dev/javascript/gleam_stdlib/gleam@dynamic@decode.erl +1114 -0
  175. package/tui/build/dev/javascript/gleam_stdlib/gleam@float.erl +711 -0
  176. package/tui/build/dev/javascript/gleam_stdlib/gleam@function.erl +18 -0
  177. package/tui/build/dev/javascript/gleam_stdlib/gleam@int.erl +972 -0
  178. package/tui/build/dev/javascript/gleam_stdlib/gleam@io.erl +76 -0
  179. package/tui/build/dev/javascript/gleam_stdlib/gleam@list.erl +2735 -0
  180. package/tui/build/dev/javascript/gleam_stdlib/gleam@option.erl +381 -0
  181. package/tui/build/dev/javascript/gleam_stdlib/gleam@order.erl +188 -0
  182. package/tui/build/dev/javascript/gleam_stdlib/gleam@pair.erl +104 -0
  183. package/tui/build/dev/javascript/gleam_stdlib/gleam@result.erl +500 -0
  184. package/tui/build/dev/javascript/gleam_stdlib/gleam@set.erl +430 -0
  185. package/tui/build/dev/javascript/gleam_stdlib/gleam@string.erl +964 -0
  186. package/tui/build/dev/javascript/gleam_stdlib/gleam@string_tree.erl +202 -0
  187. package/tui/build/dev/javascript/gleam_stdlib/gleam@uri.erl +1042 -0
  188. package/tui/build/dev/javascript/gleam_stdlib/gleam_stdlib.erl +534 -0
  189. package/tui/build/dev/javascript/gleam_stdlib/gleam_stdlib.mjs +1133 -0
  190. package/tui/build/dev/javascript/gleam_version +1 -0
  191. package/tui/build/dev/javascript/prelude.mjs +1575 -0
  192. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache +0 -0
  193. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_inline +0 -0
  194. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_meta +0 -0
  195. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_warnings +0 -0
  196. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache +0 -0
  197. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_inline +0 -0
  198. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_meta +0 -0
  199. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_warnings +0 -0
  200. package/tui/build/dev/javascript/tui/gleam.mjs +1 -0
  201. package/tui/build/dev/javascript/tui/tui/prompt.mjs +521 -0
  202. package/tui/build/dev/javascript/tui/tui.mjs +334 -0
  203. package/tui/build/dev/javascript/tui/tui_ffi.mjs +32 -0
@@ -0,0 +1,386 @@
1
+ import {
2
+ Ok,
3
+ Error,
4
+ toList,
5
+ Empty as $Empty,
6
+ prepend as listPrepend,
7
+ CustomType as $CustomType,
8
+ } from "../gleam.mjs";
9
+
10
+ export class Some extends $CustomType {
11
+ constructor($0) {
12
+ super();
13
+ this[0] = $0;
14
+ }
15
+ }
16
+ export const Option$Some = ($0) => new Some($0);
17
+ export const Option$isSome = (value) => value instanceof Some;
18
+ export const Option$Some$0 = (value) => value[0];
19
+
20
+ export class None extends $CustomType {}
21
+ export const Option$None = () => new None();
22
+ export const Option$isNone = (value) => value instanceof None;
23
+
24
+ function reverse_and_prepend(loop$prefix, loop$suffix) {
25
+ while (true) {
26
+ let prefix = loop$prefix;
27
+ let suffix = loop$suffix;
28
+ if (prefix instanceof $Empty) {
29
+ return suffix;
30
+ } else {
31
+ let first = prefix.head;
32
+ let rest = prefix.tail;
33
+ loop$prefix = rest;
34
+ loop$suffix = listPrepend(first, suffix);
35
+ }
36
+ }
37
+ }
38
+
39
+ function reverse(list) {
40
+ return reverse_and_prepend(list, toList([]));
41
+ }
42
+
43
+ function all_loop(loop$list, loop$acc) {
44
+ while (true) {
45
+ let list = loop$list;
46
+ let acc = loop$acc;
47
+ if (list instanceof $Empty) {
48
+ return new Some(reverse(acc));
49
+ } else {
50
+ let $ = list.head;
51
+ if ($ instanceof Some) {
52
+ let rest = list.tail;
53
+ let first = $[0];
54
+ loop$list = rest;
55
+ loop$acc = listPrepend(first, acc);
56
+ } else {
57
+ return new None();
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Combines a list of `Option`s into a single `Option`.
65
+ * If all elements in the list are `Some` then returns a `Some` holding the list of values.
66
+ * If any element is `None` then returns `None`.
67
+ *
68
+ * ## Examples
69
+ *
70
+ * ```gleam
71
+ * assert all([Some(1), Some(2)]) == Some([1, 2])
72
+ * ```
73
+ *
74
+ * ```gleam
75
+ * assert all([Some(1), None]) == None
76
+ * ```
77
+ */
78
+ export function all(list) {
79
+ return all_loop(list, toList([]));
80
+ }
81
+
82
+ /**
83
+ * Checks whether the `Option` is a `Some` value.
84
+ *
85
+ * ## Examples
86
+ *
87
+ * ```gleam
88
+ * assert is_some(Some(1))
89
+ * ```
90
+ *
91
+ * ```gleam
92
+ * assert !is_some(None)
93
+ * ```
94
+ */
95
+ export function is_some(option) {
96
+ return !(option instanceof None);
97
+ }
98
+
99
+ /**
100
+ * Checks whether the `Option` is a `None` value.
101
+ *
102
+ * ## Examples
103
+ *
104
+ * ```gleam
105
+ * assert !is_none(Some(1))
106
+ * ```
107
+ *
108
+ * ```gleam
109
+ * assert is_none(None)
110
+ * ```
111
+ */
112
+ export function is_none(option) {
113
+ return option instanceof None;
114
+ }
115
+
116
+ /**
117
+ * Converts an `Option` type to a `Result` type.
118
+ *
119
+ * ## Examples
120
+ *
121
+ * ```gleam
122
+ * assert to_result(Some(1), "some_error") == Ok(1)
123
+ * ```
124
+ *
125
+ * ```gleam
126
+ * assert to_result(None, "some_error") == Error("some_error")
127
+ * ```
128
+ */
129
+ export function to_result(option, e) {
130
+ if (option instanceof Some) {
131
+ let a = option[0];
132
+ return new Ok(a);
133
+ } else {
134
+ return new Error(e);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Converts a `Result` type to an `Option` type.
140
+ *
141
+ * ## Examples
142
+ *
143
+ * ```gleam
144
+ * assert from_result(Ok(1)) == Some(1)
145
+ * ```
146
+ *
147
+ * ```gleam
148
+ * assert from_result(Error("some_error")) == None
149
+ * ```
150
+ */
151
+ export function from_result(result) {
152
+ if (result instanceof Ok) {
153
+ let a = result[0];
154
+ return new Some(a);
155
+ } else {
156
+ return new None();
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Extracts the value from an `Option`, returning a default value if there is none.
162
+ *
163
+ * ## Examples
164
+ *
165
+ * ```gleam
166
+ * assert unwrap(Some(1), 0) == 1
167
+ * ```
168
+ *
169
+ * ```gleam
170
+ * assert unwrap(None, 0) == 0
171
+ * ```
172
+ */
173
+ export function unwrap(option, default$) {
174
+ if (option instanceof Some) {
175
+ let x = option[0];
176
+ return x;
177
+ } else {
178
+ return default$;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Extracts the value from an `Option`, evaluating the default function if the option is `None`.
184
+ *
185
+ * ## Examples
186
+ *
187
+ * ```gleam
188
+ * assert lazy_unwrap(Some(1), fn() { 0 }) == 1
189
+ * ```
190
+ *
191
+ * ```gleam
192
+ * assert lazy_unwrap(None, fn() { 0 }) == 0
193
+ * ```
194
+ */
195
+ export function lazy_unwrap(option, default$) {
196
+ if (option instanceof Some) {
197
+ let x = option[0];
198
+ return x;
199
+ } else {
200
+ return default$();
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Updates a value held within the `Some` of an `Option` by calling a given function
206
+ * on it.
207
+ *
208
+ * If the `Option` is a `None` rather than `Some`, the function is not called and the
209
+ * `Option` stays the same.
210
+ *
211
+ * ## Examples
212
+ *
213
+ * ```gleam
214
+ * assert map(over: Some(1), with: fn(x) { x + 1 }) == Some(2)
215
+ * ```
216
+ *
217
+ * ```gleam
218
+ * assert map(over: None, with: fn(x) { x + 1 }) == None
219
+ * ```
220
+ */
221
+ export function map(option, fun) {
222
+ if (option instanceof Some) {
223
+ let x = option[0];
224
+ return new Some(fun(x));
225
+ } else {
226
+ return option;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Merges a nested `Option` into a single layer.
232
+ *
233
+ * ## Examples
234
+ *
235
+ * ```gleam
236
+ * assert flatten(Some(Some(1))) == Some(1)
237
+ * ```
238
+ *
239
+ * ```gleam
240
+ * assert flatten(Some(None)) == None
241
+ * ```
242
+ *
243
+ * ```gleam
244
+ * assert flatten(None) == None
245
+ * ```
246
+ */
247
+ export function flatten(option) {
248
+ if (option instanceof Some) {
249
+ let x = option[0];
250
+ return x;
251
+ } else {
252
+ return option;
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Updates a value held within the `Some` of an `Option` by calling a given function
258
+ * on it, where the given function also returns an `Option`. The two options are
259
+ * then merged together into one `Option`.
260
+ *
261
+ * If the `Option` is a `None` rather than `Some` the function is not called and the
262
+ * option stays the same.
263
+ *
264
+ * This function is the equivalent of calling `map` followed by `flatten`, and
265
+ * it is useful for chaining together multiple functions that return `Option`.
266
+ *
267
+ * ## Examples
268
+ *
269
+ * ```gleam
270
+ * assert then(Some(1), fn(x) { Some(x + 1) }) == Some(2)
271
+ * ```
272
+ *
273
+ * ```gleam
274
+ * assert then(Some(1), fn(x) { Some(#("a", x)) }) == Some(#("a", 1))
275
+ * ```
276
+ *
277
+ * ```gleam
278
+ * assert then(Some(1), fn(_) { None }) == None
279
+ * ```
280
+ *
281
+ * ```gleam
282
+ * assert then(None, fn(x) { Some(x + 1) }) == None
283
+ * ```
284
+ */
285
+ export function then$(option, fun) {
286
+ if (option instanceof Some) {
287
+ let x = option[0];
288
+ return fun(x);
289
+ } else {
290
+ return option;
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Returns the first value if it is `Some`, otherwise returns the second value.
296
+ *
297
+ * ## Examples
298
+ *
299
+ * ```gleam
300
+ * assert or(Some(1), Some(2)) == Some(1)
301
+ * ```
302
+ *
303
+ * ```gleam
304
+ * assert or(Some(1), None) == Some(1)
305
+ * ```
306
+ *
307
+ * ```gleam
308
+ * assert or(None, Some(2)) == Some(2)
309
+ * ```
310
+ *
311
+ * ```gleam
312
+ * assert or(None, None) == None
313
+ * ```
314
+ */
315
+ export function or(first, second) {
316
+ if (first instanceof Some) {
317
+ return first;
318
+ } else {
319
+ return second;
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Returns the first value if it is `Some`, otherwise evaluates the given function for a fallback value.
325
+ *
326
+ * ## Examples
327
+ *
328
+ * ```gleam
329
+ * assert lazy_or(Some(1), fn() { Some(2) }) == Some(1)
330
+ * ```
331
+ *
332
+ * ```gleam
333
+ * assert lazy_or(Some(1), fn() { None }) == Some(1)
334
+ * ```
335
+ *
336
+ * ```gleam
337
+ * assert lazy_or(None, fn() { Some(2) }) == Some(2)
338
+ * ```
339
+ *
340
+ * ```gleam
341
+ * assert lazy_or(None, fn() { None }) == None
342
+ * ```
343
+ */
344
+ export function lazy_or(first, second) {
345
+ if (first instanceof Some) {
346
+ return first;
347
+ } else {
348
+ return second();
349
+ }
350
+ }
351
+
352
+ function values_loop(loop$list, loop$acc) {
353
+ while (true) {
354
+ let list = loop$list;
355
+ let acc = loop$acc;
356
+ if (list instanceof $Empty) {
357
+ return reverse(acc);
358
+ } else {
359
+ let $ = list.head;
360
+ if ($ instanceof Some) {
361
+ let rest = list.tail;
362
+ let first = $[0];
363
+ loop$list = rest;
364
+ loop$acc = listPrepend(first, acc);
365
+ } else {
366
+ let rest = list.tail;
367
+ loop$list = rest;
368
+ loop$acc = acc;
369
+ }
370
+ }
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Given a list of `Option`s,
376
+ * returns only the values inside `Some`.
377
+ *
378
+ * ## Examples
379
+ *
380
+ * ```gleam
381
+ * assert values([Some(1), None, Some(3)]) == [1, 3]
382
+ * ```
383
+ */
384
+ export function values(options) {
385
+ return values_loop(options, toList([]));
386
+ }
@@ -0,0 +1,166 @@
1
+ import { CustomType as $CustomType, isEqual } from "../gleam.mjs";
2
+
3
+ export class Lt extends $CustomType {}
4
+ export const Order$Lt = () => new Lt();
5
+ export const Order$isLt = (value) => value instanceof Lt;
6
+
7
+ export class Eq extends $CustomType {}
8
+ export const Order$Eq = () => new Eq();
9
+ export const Order$isEq = (value) => value instanceof Eq;
10
+
11
+ export class Gt extends $CustomType {}
12
+ export const Order$Gt = () => new Gt();
13
+ export const Order$isGt = (value) => value instanceof Gt;
14
+
15
+ /**
16
+ * Inverts an order, so less-than becomes greater-than and greater-than
17
+ * becomes less-than.
18
+ *
19
+ * ## Examples
20
+ *
21
+ * ```gleam
22
+ * assert negate(Lt) == Gt
23
+ * ```
24
+ *
25
+ * ```gleam
26
+ * assert negate(Eq) == Eq
27
+ * ```
28
+ *
29
+ * ```gleam
30
+ * assert negate(Gt) == Lt
31
+ * ```
32
+ */
33
+ export function negate(order) {
34
+ if (order instanceof Lt) {
35
+ return new Gt();
36
+ } else if (order instanceof Eq) {
37
+ return order;
38
+ } else {
39
+ return new Lt();
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Produces a numeric representation of the order.
45
+ *
46
+ * ## Examples
47
+ *
48
+ * ```gleam
49
+ * assert to_int(Lt) == -1
50
+ * ```
51
+ *
52
+ * ```gleam
53
+ * assert to_int(Eq) == 0
54
+ * ```
55
+ *
56
+ * ```gleam
57
+ * assert to_int(Gt) == 1
58
+ * ```
59
+ */
60
+ export function to_int(order) {
61
+ if (order instanceof Lt) {
62
+ return -1;
63
+ } else if (order instanceof Eq) {
64
+ return 0;
65
+ } else {
66
+ return 1;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Compares two `Order` values to one another, producing a new `Order`.
72
+ *
73
+ * ## Examples
74
+ *
75
+ * ```gleam
76
+ * assert compare(Eq, with: Lt) == Gt
77
+ * ```
78
+ */
79
+ export function compare(a, b) {
80
+ let x = a;
81
+ let y = b;
82
+ if (isEqual(x, y)) {
83
+ return new Eq();
84
+ } else if (a instanceof Lt) {
85
+ return new Lt();
86
+ } else if (a instanceof Eq && b instanceof Gt) {
87
+ return new Lt();
88
+ } else {
89
+ return new Gt();
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Inverts an ordering function, so less-than becomes greater-than and greater-than
95
+ * becomes less-than.
96
+ *
97
+ * ## Examples
98
+ *
99
+ * ```gleam
100
+ * import gleam/int
101
+ * import gleam/list
102
+ *
103
+ * assert list.sort([1, 5, 4], by: reverse(int.compare)) == [5, 4, 1]
104
+ * ```
105
+ */
106
+ export function reverse(orderer) {
107
+ return (a, b) => { return orderer(b, a); };
108
+ }
109
+
110
+ /**
111
+ * Return a fallback `Order` in case the first argument is `Eq`.
112
+ *
113
+ * ## Examples
114
+ *
115
+ * ```gleam
116
+ * import gleam/int
117
+ *
118
+ * assert break_tie(in: int.compare(1, 1), with: Lt) == Lt
119
+ * ```
120
+ *
121
+ * ```gleam
122
+ * import gleam/int
123
+ *
124
+ * assert break_tie(in: int.compare(1, 0), with: Eq) == Gt
125
+ * ```
126
+ */
127
+ export function break_tie(order, other) {
128
+ if (order instanceof Lt) {
129
+ return order;
130
+ } else if (order instanceof Eq) {
131
+ return other;
132
+ } else {
133
+ return order;
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Invokes a fallback function returning an `Order` in case the first argument
139
+ * is `Eq`.
140
+ *
141
+ * This can be useful when the fallback comparison might be expensive and it
142
+ * needs to be delayed until strictly necessary.
143
+ *
144
+ * ## Examples
145
+ *
146
+ * ```gleam
147
+ * import gleam/int
148
+ *
149
+ * assert lazy_break_tie(in: int.compare(1, 1), with: fn() { Lt }) == Lt
150
+ * ```
151
+ *
152
+ * ```gleam
153
+ * import gleam/int
154
+ *
155
+ * assert lazy_break_tie(in: int.compare(1, 0), with: fn() { Eq }) == Gt
156
+ * ```
157
+ */
158
+ export function lazy_break_tie(order, comparison) {
159
+ if (order instanceof Lt) {
160
+ return order;
161
+ } else if (order instanceof Eq) {
162
+ return comparison();
163
+ } else {
164
+ return order;
165
+ }
166
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Returns the first element in a pair.
3
+ *
4
+ * ## Examples
5
+ *
6
+ * ```gleam
7
+ * assert first(#(1, 2)) == 1
8
+ * ```
9
+ */
10
+ export function first(pair) {
11
+ let a;
12
+ a = pair[0];
13
+ return a;
14
+ }
15
+
16
+ /**
17
+ * Returns the second element in a pair.
18
+ *
19
+ * ## Examples
20
+ *
21
+ * ```gleam
22
+ * assert second(#(1, 2)) == 2
23
+ * ```
24
+ */
25
+ export function second(pair) {
26
+ let a;
27
+ a = pair[1];
28
+ return a;
29
+ }
30
+
31
+ /**
32
+ * Returns a new pair with the elements swapped.
33
+ *
34
+ * ## Examples
35
+ *
36
+ * ```gleam
37
+ * assert swap(#(1, 2)) == #(2, 1)
38
+ * ```
39
+ */
40
+ export function swap(pair) {
41
+ let a;
42
+ let b;
43
+ a = pair[0];
44
+ b = pair[1];
45
+ return [b, a];
46
+ }
47
+
48
+ /**
49
+ * Returns a new pair with the first element having had `with` applied to
50
+ * it.
51
+ *
52
+ * ## Examples
53
+ *
54
+ * ```gleam
55
+ * assert #(1, 2) |> map_first(fn(n) { n * 2 }) == #(2, 2)
56
+ * ```
57
+ */
58
+ export function map_first(pair, fun) {
59
+ let a;
60
+ let b;
61
+ a = pair[0];
62
+ b = pair[1];
63
+ return [fun(a), b];
64
+ }
65
+
66
+ /**
67
+ * Returns a new pair with the second element having had `with` applied to
68
+ * it.
69
+ *
70
+ * ## Examples
71
+ *
72
+ * ```gleam
73
+ * assert #(1, 2) |> map_second(fn(n) { n * 2 }) == #(1, 4)
74
+ * ```
75
+ */
76
+ export function map_second(pair, fun) {
77
+ let a;
78
+ let b;
79
+ a = pair[0];
80
+ b = pair[1];
81
+ return [a, fun(b)];
82
+ }
83
+
84
+ /**
85
+ * Returns a new pair with the given elements. This can also be done using the dedicated
86
+ * syntax instead: `new(1, 2) == #(1, 2)`.
87
+ *
88
+ * ## Examples
89
+ *
90
+ * ```gleam
91
+ * assert new(1, 2) == #(1, 2)
92
+ * ```
93
+ */
94
+ export function new$(first, second) {
95
+ return [first, second];
96
+ }