skill-universe 1.1.0

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 (334) hide show
  1. package/README.md +24 -0
  2. package/bin/skillc.mjs +3 -0
  3. package/build/dev/javascript/argv/_gleam_artefacts/argv.cache +0 -0
  4. package/build/dev/javascript/argv/_gleam_artefacts/argv.cache_inline +0 -0
  5. package/build/dev/javascript/argv/_gleam_artefacts/argv.cache_meta +0 -0
  6. package/build/dev/javascript/argv/argv.erl +12 -0
  7. package/build/dev/javascript/argv/argv.mjs +31 -0
  8. package/build/dev/javascript/argv/argv_ffi.erl +27 -0
  9. package/build/dev/javascript/argv/argv_ffi.mjs +20 -0
  10. package/build/dev/javascript/argv/gleam.mjs +1 -0
  11. package/build/dev/javascript/filepath/_gleam_artefacts/filepath.cache +0 -0
  12. package/build/dev/javascript/filepath/_gleam_artefacts/filepath.cache_inline +0 -0
  13. package/build/dev/javascript/filepath/_gleam_artefacts/filepath.cache_meta +0 -0
  14. package/build/dev/javascript/filepath/filepath.erl +425 -0
  15. package/build/dev/javascript/filepath/filepath.mjs +529 -0
  16. package/build/dev/javascript/filepath/filepath_ffi.erl +9 -0
  17. package/build/dev/javascript/filepath/filepath_ffi.mjs +6 -0
  18. package/build/dev/javascript/filepath/gleam.mjs +1 -0
  19. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache +0 -0
  20. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_inline +0 -0
  21. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta +0 -0
  22. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache +0 -0
  23. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_inline +0 -0
  24. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta +0 -0
  25. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache +0 -0
  26. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_inline +0 -0
  27. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_meta +0 -0
  28. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache +0 -0
  29. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_inline +0 -0
  30. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta +0 -0
  31. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache +0 -0
  32. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_inline +0 -0
  33. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta +0 -0
  34. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache +0 -0
  35. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_inline +0 -0
  36. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_meta +0 -0
  37. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache +0 -0
  38. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_inline +0 -0
  39. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta +0 -0
  40. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache +0 -0
  41. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_inline +0 -0
  42. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta +0 -0
  43. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache +0 -0
  44. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_inline +0 -0
  45. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta +0 -0
  46. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache +0 -0
  47. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_inline +0 -0
  48. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta +0 -0
  49. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache +0 -0
  50. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_inline +0 -0
  51. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta +0 -0
  52. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache +0 -0
  53. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_inline +0 -0
  54. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta +0 -0
  55. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache +0 -0
  56. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_inline +0 -0
  57. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta +0 -0
  58. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache +0 -0
  59. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_inline +0 -0
  60. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta +0 -0
  61. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache +0 -0
  62. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_inline +0 -0
  63. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta +0 -0
  64. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache +0 -0
  65. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_inline +0 -0
  66. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta +0 -0
  67. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache +0 -0
  68. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_inline +0 -0
  69. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta +0 -0
  70. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache +0 -0
  71. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_inline +0 -0
  72. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_meta +0 -0
  73. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache +0 -0
  74. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_inline +0 -0
  75. package/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta +0 -0
  76. package/build/dev/javascript/gleam_stdlib/dict.mjs +710 -0
  77. package/build/dev/javascript/gleam_stdlib/gleam/bit_array.mjs +285 -0
  78. package/build/dev/javascript/gleam_stdlib/gleam/bool.mjs +313 -0
  79. package/build/dev/javascript/gleam_stdlib/gleam/bytes_tree.mjs +225 -0
  80. package/build/dev/javascript/gleam_stdlib/gleam/dict.mjs +456 -0
  81. package/build/dev/javascript/gleam_stdlib/gleam/dynamic/decode.mjs +985 -0
  82. package/build/dev/javascript/gleam_stdlib/gleam/dynamic.mjs +35 -0
  83. package/build/dev/javascript/gleam_stdlib/gleam/float.mjs +572 -0
  84. package/build/dev/javascript/gleam_stdlib/gleam/function.mjs +6 -0
  85. package/build/dev/javascript/gleam_stdlib/gleam/int.mjs +832 -0
  86. package/build/dev/javascript/gleam_stdlib/gleam/io.mjs +8 -0
  87. package/build/dev/javascript/gleam_stdlib/gleam/list.mjs +3160 -0
  88. package/build/dev/javascript/gleam_stdlib/gleam/option.mjs +418 -0
  89. package/build/dev/javascript/gleam_stdlib/gleam/order.mjs +178 -0
  90. package/build/dev/javascript/gleam_stdlib/gleam/pair.mjs +102 -0
  91. package/build/dev/javascript/gleam_stdlib/gleam/result.mjs +480 -0
  92. package/build/dev/javascript/gleam_stdlib/gleam/set.mjs +416 -0
  93. package/build/dev/javascript/gleam_stdlib/gleam/string.mjs +723 -0
  94. package/build/dev/javascript/gleam_stdlib/gleam/string_tree.mjs +133 -0
  95. package/build/dev/javascript/gleam_stdlib/gleam/uri.mjs +1155 -0
  96. package/build/dev/javascript/gleam_stdlib/gleam.mjs +1 -0
  97. package/build/dev/javascript/gleam_stdlib/gleam@bit_array.erl +347 -0
  98. package/build/dev/javascript/gleam_stdlib/gleam@bool.erl +352 -0
  99. package/build/dev/javascript/gleam_stdlib/gleam@bytes_tree.erl +211 -0
  100. package/build/dev/javascript/gleam_stdlib/gleam@dict.erl +521 -0
  101. package/build/dev/javascript/gleam_stdlib/gleam@dynamic.erl +106 -0
  102. package/build/dev/javascript/gleam_stdlib/gleam@dynamic@decode.erl +1112 -0
  103. package/build/dev/javascript/gleam_stdlib/gleam@float.erl +764 -0
  104. package/build/dev/javascript/gleam_stdlib/gleam@function.erl +18 -0
  105. package/build/dev/javascript/gleam_stdlib/gleam@int.erl +1004 -0
  106. package/build/dev/javascript/gleam_stdlib/gleam@io.erl +80 -0
  107. package/build/dev/javascript/gleam_stdlib/gleam@list.erl +2832 -0
  108. package/build/dev/javascript/gleam_stdlib/gleam@option.erl +413 -0
  109. package/build/dev/javascript/gleam_stdlib/gleam@order.erl +200 -0
  110. package/build/dev/javascript/gleam_stdlib/gleam@pair.erl +110 -0
  111. package/build/dev/javascript/gleam_stdlib/gleam@result.erl +532 -0
  112. package/build/dev/javascript/gleam_stdlib/gleam@set.erl +433 -0
  113. package/build/dev/javascript/gleam_stdlib/gleam@string.erl +1012 -0
  114. package/build/dev/javascript/gleam_stdlib/gleam@string_tree.erl +207 -0
  115. package/build/dev/javascript/gleam_stdlib/gleam@uri.erl +1049 -0
  116. package/build/dev/javascript/gleam_stdlib/gleam_stdlib.erl +529 -0
  117. package/build/dev/javascript/gleam_stdlib/gleam_stdlib.mjs +1050 -0
  118. package/build/dev/javascript/gleam_version +1 -0
  119. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit.cache +0 -0
  120. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit.cache_inline +0 -0
  121. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit.cache_meta +0 -0
  122. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@gleam_panic.cache +0 -0
  123. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@gleam_panic.cache_inline +0 -0
  124. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@gleam_panic.cache_meta +0 -0
  125. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@reporting.cache +0 -0
  126. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@reporting.cache_inline +0 -0
  127. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@internal@reporting.cache_meta +0 -0
  128. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@should.cache +0 -0
  129. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@should.cache_inline +0 -0
  130. package/build/dev/javascript/gleeunit/_gleam_artefacts/gleeunit@should.cache_meta +0 -0
  131. package/build/dev/javascript/gleeunit/gleam.mjs +1 -0
  132. package/build/dev/javascript/gleeunit/gleeunit/internal/gleam_panic.mjs +180 -0
  133. package/build/dev/javascript/gleeunit/gleeunit/internal/gleeunit_gleam_panic_ffi.erl +49 -0
  134. package/build/dev/javascript/gleeunit/gleeunit/internal/gleeunit_gleam_panic_ffi.mjs +91 -0
  135. package/build/dev/javascript/gleeunit/gleeunit/internal/reporting.mjs +256 -0
  136. package/build/dev/javascript/gleeunit/gleeunit/should.mjs +135 -0
  137. package/build/dev/javascript/gleeunit/gleeunit.erl +89 -0
  138. package/build/dev/javascript/gleeunit/gleeunit.mjs +62 -0
  139. package/build/dev/javascript/gleeunit/gleeunit@internal@gleam_panic.erl +56 -0
  140. package/build/dev/javascript/gleeunit/gleeunit@internal@reporting.erl +343 -0
  141. package/build/dev/javascript/gleeunit/gleeunit@should.erl +153 -0
  142. package/build/dev/javascript/gleeunit/gleeunit_ffi.erl +21 -0
  143. package/build/dev/javascript/gleeunit/gleeunit_ffi.mjs +100 -0
  144. package/build/dev/javascript/gleeunit/gleeunit_progress.erl +72 -0
  145. package/build/dev/javascript/prelude.mjs +1575 -0
  146. package/build/dev/javascript/simplifile/_gleam_artefacts/simplifile.cache +0 -0
  147. package/build/dev/javascript/simplifile/_gleam_artefacts/simplifile.cache_inline +0 -0
  148. package/build/dev/javascript/simplifile/_gleam_artefacts/simplifile.cache_meta +0 -0
  149. package/build/dev/javascript/simplifile/gleam.mjs +1 -0
  150. package/build/dev/javascript/simplifile/simplifile.erl +893 -0
  151. package/build/dev/javascript/simplifile/simplifile.mjs +893 -0
  152. package/build/dev/javascript/simplifile/simplifile_erl.erl +244 -0
  153. package/build/dev/javascript/simplifile/simplifile_js.mjs +400 -0
  154. package/build/dev/javascript/skillc/_gleam_artefacts/cli_test.cache +0 -0
  155. package/build/dev/javascript/skillc/_gleam_artefacts/cli_test.cache_inline +0 -0
  156. package/build/dev/javascript/skillc/_gleam_artefacts/cli_test.cache_meta +0 -0
  157. package/build/dev/javascript/skillc/_gleam_artefacts/cli_test.cache_warnings +0 -0
  158. package/build/dev/javascript/skillc/_gleam_artefacts/compiler_test.cache +0 -0
  159. package/build/dev/javascript/skillc/_gleam_artefacts/compiler_test.cache_inline +0 -0
  160. package/build/dev/javascript/skillc/_gleam_artefacts/compiler_test.cache_meta +0 -0
  161. package/build/dev/javascript/skillc/_gleam_artefacts/compiler_test.cache_warnings +0 -0
  162. package/build/dev/javascript/skillc/_gleam_artefacts/config_test.cache +0 -0
  163. package/build/dev/javascript/skillc/_gleam_artefacts/config_test.cache_inline +0 -0
  164. package/build/dev/javascript/skillc/_gleam_artefacts/config_test.cache_meta +0 -0
  165. package/build/dev/javascript/skillc/_gleam_artefacts/config_test.cache_warnings +0 -0
  166. package/build/dev/javascript/skillc/_gleam_artefacts/importer_test.cache +0 -0
  167. package/build/dev/javascript/skillc/_gleam_artefacts/importer_test.cache_inline +0 -0
  168. package/build/dev/javascript/skillc/_gleam_artefacts/importer_test.cache_meta +0 -0
  169. package/build/dev/javascript/skillc/_gleam_artefacts/importer_test.cache_warnings +0 -0
  170. package/build/dev/javascript/skillc/_gleam_artefacts/parser_test.cache +0 -0
  171. package/build/dev/javascript/skillc/_gleam_artefacts/parser_test.cache_inline +0 -0
  172. package/build/dev/javascript/skillc/_gleam_artefacts/parser_test.cache_meta +0 -0
  173. package/build/dev/javascript/skillc/_gleam_artefacts/parser_test.cache_warnings +0 -0
  174. package/build/dev/javascript/skillc/_gleam_artefacts/path_test.cache +0 -0
  175. package/build/dev/javascript/skillc/_gleam_artefacts/path_test.cache_inline +0 -0
  176. package/build/dev/javascript/skillc/_gleam_artefacts/path_test.cache_meta +0 -0
  177. package/build/dev/javascript/skillc/_gleam_artefacts/path_test.cache_warnings +0 -0
  178. package/build/dev/javascript/skillc/_gleam_artefacts/provider_test.cache +0 -0
  179. package/build/dev/javascript/skillc/_gleam_artefacts/provider_test.cache_inline +0 -0
  180. package/build/dev/javascript/skillc/_gleam_artefacts/provider_test.cache_meta +0 -0
  181. package/build/dev/javascript/skillc/_gleam_artefacts/provider_test.cache_warnings +0 -0
  182. package/build/dev/javascript/skillc/_gleam_artefacts/registry_test.cache +0 -0
  183. package/build/dev/javascript/skillc/_gleam_artefacts/registry_test.cache_inline +0 -0
  184. package/build/dev/javascript/skillc/_gleam_artefacts/registry_test.cache_meta +0 -0
  185. package/build/dev/javascript/skillc/_gleam_artefacts/registry_test.cache_warnings +0 -0
  186. package/build/dev/javascript/skillc/_gleam_artefacts/scaffold_test.cache +0 -0
  187. package/build/dev/javascript/skillc/_gleam_artefacts/scaffold_test.cache_inline +0 -0
  188. package/build/dev/javascript/skillc/_gleam_artefacts/scaffold_test.cache_meta +0 -0
  189. package/build/dev/javascript/skillc/_gleam_artefacts/scaffold_test.cache_warnings +0 -0
  190. package/build/dev/javascript/skillc/_gleam_artefacts/skillc.cache +0 -0
  191. package/build/dev/javascript/skillc/_gleam_artefacts/skillc.cache_inline +0 -0
  192. package/build/dev/javascript/skillc/_gleam_artefacts/skillc.cache_meta +0 -0
  193. package/build/dev/javascript/skillc/_gleam_artefacts/skillc.cache_warnings +0 -0
  194. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@compiler.cache +0 -0
  195. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@compiler.cache_inline +0 -0
  196. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@compiler.cache_meta +0 -0
  197. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@compiler.cache_warnings +0 -0
  198. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@config.cache +0 -0
  199. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@config.cache_inline +0 -0
  200. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@config.cache_meta +0 -0
  201. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@config.cache_warnings +0 -0
  202. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@error.cache +0 -0
  203. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@error.cache_inline +0 -0
  204. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@error.cache_meta +0 -0
  205. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@error.cache_warnings +0 -0
  206. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@fs.cache +0 -0
  207. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@fs.cache_inline +0 -0
  208. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@fs.cache_meta +0 -0
  209. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@fs.cache_warnings +0 -0
  210. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@importer.cache +0 -0
  211. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@importer.cache_inline +0 -0
  212. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@importer.cache_meta +0 -0
  213. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@importer.cache_warnings +0 -0
  214. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@parser.cache +0 -0
  215. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@parser.cache_inline +0 -0
  216. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@parser.cache_meta +0 -0
  217. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@parser.cache_warnings +0 -0
  218. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@path.cache +0 -0
  219. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@path.cache_inline +0 -0
  220. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@path.cache_meta +0 -0
  221. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@path.cache_warnings +0 -0
  222. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@platform.cache +0 -0
  223. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@platform.cache_inline +0 -0
  224. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@platform.cache_meta +0 -0
  225. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@platform.cache_warnings +0 -0
  226. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@provider.cache +0 -0
  227. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@provider.cache_inline +0 -0
  228. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@provider.cache_meta +0 -0
  229. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@provider.cache_warnings +0 -0
  230. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@registry.cache +0 -0
  231. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@registry.cache_inline +0 -0
  232. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@registry.cache_meta +0 -0
  233. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@registry.cache_warnings +0 -0
  234. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@scaffold.cache +0 -0
  235. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@scaffold.cache_inline +0 -0
  236. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@scaffold.cache_meta +0 -0
  237. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@scaffold.cache_warnings +0 -0
  238. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@semver.cache +0 -0
  239. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@semver.cache_inline +0 -0
  240. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@semver.cache_meta +0 -0
  241. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@semver.cache_warnings +0 -0
  242. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@shell.cache +0 -0
  243. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@shell.cache_inline +0 -0
  244. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@shell.cache_meta +0 -0
  245. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@shell.cache_warnings +0 -0
  246. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@template.cache +0 -0
  247. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@template.cache_inline +0 -0
  248. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@template.cache_meta +0 -0
  249. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@template.cache_warnings +0 -0
  250. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@types.cache +0 -0
  251. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@types.cache_inline +0 -0
  252. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@types.cache_meta +0 -0
  253. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@types.cache_warnings +0 -0
  254. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@version_constraint.cache +0 -0
  255. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@version_constraint.cache_inline +0 -0
  256. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@version_constraint.cache_meta +0 -0
  257. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@version_constraint.cache_warnings +0 -0
  258. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@yaml.cache +0 -0
  259. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@yaml.cache_inline +0 -0
  260. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@yaml.cache_meta +0 -0
  261. package/build/dev/javascript/skillc/_gleam_artefacts/skillc@yaml.cache_warnings +0 -0
  262. package/build/dev/javascript/skillc/_gleam_artefacts/skillc_test.cache +0 -0
  263. package/build/dev/javascript/skillc/_gleam_artefacts/skillc_test.cache_inline +0 -0
  264. package/build/dev/javascript/skillc/_gleam_artefacts/skillc_test.cache_meta +0 -0
  265. package/build/dev/javascript/skillc/_gleam_artefacts/skillc_test.cache_warnings +0 -0
  266. package/build/dev/javascript/skillc/_gleam_artefacts/template_test.cache +0 -0
  267. package/build/dev/javascript/skillc/_gleam_artefacts/template_test.cache_inline +0 -0
  268. package/build/dev/javascript/skillc/_gleam_artefacts/template_test.cache_meta +0 -0
  269. package/build/dev/javascript/skillc/_gleam_artefacts/template_test.cache_warnings +0 -0
  270. package/build/dev/javascript/skillc/_gleam_artefacts/version_constraint_test.cache +0 -0
  271. package/build/dev/javascript/skillc/_gleam_artefacts/version_constraint_test.cache_inline +0 -0
  272. package/build/dev/javascript/skillc/_gleam_artefacts/version_constraint_test.cache_meta +0 -0
  273. package/build/dev/javascript/skillc/_gleam_artefacts/version_constraint_test.cache_warnings +0 -0
  274. package/build/dev/javascript/skillc/cli_test.mjs +461 -0
  275. package/build/dev/javascript/skillc/compiler_test.mjs +3089 -0
  276. package/build/dev/javascript/skillc/config_test.mjs +308 -0
  277. package/build/dev/javascript/skillc/gleam.main.mjs +2 -0
  278. package/build/dev/javascript/skillc/gleam.mjs +1 -0
  279. package/build/dev/javascript/skillc/importer_test.mjs +1643 -0
  280. package/build/dev/javascript/skillc/parser_test.mjs +1601 -0
  281. package/build/dev/javascript/skillc/path_test.mjs +26 -0
  282. package/build/dev/javascript/skillc/provider_test.mjs +221 -0
  283. package/build/dev/javascript/skillc/registry_test.mjs +359 -0
  284. package/build/dev/javascript/skillc/scaffold_test.mjs +405 -0
  285. package/build/dev/javascript/skillc/skillc/compiler.mjs +724 -0
  286. package/build/dev/javascript/skillc/skillc/config.mjs +172 -0
  287. package/build/dev/javascript/skillc/skillc/error.mjs +145 -0
  288. package/build/dev/javascript/skillc/skillc/fs.mjs +40 -0
  289. package/build/dev/javascript/skillc/skillc/importer.mjs +975 -0
  290. package/build/dev/javascript/skillc/skillc/parser.mjs +427 -0
  291. package/build/dev/javascript/skillc/skillc/path.mjs +52 -0
  292. package/build/dev/javascript/skillc/skillc/platform.mjs +44 -0
  293. package/build/dev/javascript/skillc/skillc/provider.mjs +86 -0
  294. package/build/dev/javascript/skillc/skillc/registry.mjs +701 -0
  295. package/build/dev/javascript/skillc/skillc/scaffold.mjs +117 -0
  296. package/build/dev/javascript/skillc/skillc/semver.mjs +293 -0
  297. package/build/dev/javascript/skillc/skillc/shell.mjs +14 -0
  298. package/build/dev/javascript/skillc/skillc/template.mjs +1177 -0
  299. package/build/dev/javascript/skillc/skillc/types.mjs +249 -0
  300. package/build/dev/javascript/skillc/skillc/version_constraint.mjs +290 -0
  301. package/build/dev/javascript/skillc/skillc/yaml.mjs +51 -0
  302. package/build/dev/javascript/skillc/skillc.mjs +873 -0
  303. package/build/dev/javascript/skillc/skillc_ffi.mjs +30 -0
  304. package/build/dev/javascript/skillc/skillc_test.mjs +5 -0
  305. package/build/dev/javascript/skillc/template_test.mjs +1638 -0
  306. package/build/dev/javascript/skillc/version_constraint_test.mjs +1325 -0
  307. package/build/dev/javascript/yay/_gleam_artefacts/yay.cache +0 -0
  308. package/build/dev/javascript/yay/_gleam_artefacts/yay.cache_inline +0 -0
  309. package/build/dev/javascript/yay/_gleam_artefacts/yay.cache_meta +0 -0
  310. package/build/dev/javascript/yay/gleam.mjs +1 -0
  311. package/build/dev/javascript/yay/yaml_ffi.erl +106 -0
  312. package/build/dev/javascript/yay/yaml_ffi.mjs +373 -0
  313. package/build/dev/javascript/yay/yay.erl +1218 -0
  314. package/build/dev/javascript/yay/yay.mjs +1403 -0
  315. package/package.json +28 -0
  316. package/src/skillc/compiler.gleam +561 -0
  317. package/src/skillc/config.gleam +91 -0
  318. package/src/skillc/error.gleam +37 -0
  319. package/src/skillc/fs.gleam +31 -0
  320. package/src/skillc/importer.gleam +709 -0
  321. package/src/skillc/parser.gleam +279 -0
  322. package/src/skillc/path.gleam +30 -0
  323. package/src/skillc/platform.gleam +25 -0
  324. package/src/skillc/provider.gleam +58 -0
  325. package/src/skillc/registry.gleam +472 -0
  326. package/src/skillc/scaffold.gleam +112 -0
  327. package/src/skillc/semver.gleam +165 -0
  328. package/src/skillc/shell.gleam +12 -0
  329. package/src/skillc/template.gleam +885 -0
  330. package/src/skillc/types.gleam +93 -0
  331. package/src/skillc/version_constraint.gleam +163 -0
  332. package/src/skillc/yaml.gleam +27 -0
  333. package/src/skillc.gleam +466 -0
  334. package/src/skillc_ffi.mjs +30 -0
@@ -0,0 +1,2832 @@
1
+ -module(gleam@list).
2
+ -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
3
+ -define(FILEPATH, "src/gleam/list.gleam").
4
+ -export([length/1, count/2, reverse/1, is_empty/1, contains/2, first/1, rest/1, group/2, filter/2, filter_map/2, map/2, map2/3, map_fold/3, index_map/2, try_map/2, drop/2, take/2, new/0, wrap/1, append/2, prepend/2, flatten/1, flat_map/2, fold/3, fold_right/3, index_fold/3, try_fold/3, fold_until/3, find/2, find_map/2, all/2, any/2, zip/2, strict_zip/2, unzip/1, intersperse/2, unique/1, sort/2, range/2, repeat/2, split/2, split_while/2, key_find/2, key_filter/2, key_pop/2, key_set/3, each/2, try_each/2, partition/2, window/2, window_by_2/1, drop_while/2, take_while/2, chunk/2, sized_chunk/2, reduce/2, scan/3, last/1, combinations/2, combination_pairs/1, transpose/1, interleave/1, shuffle/1, max/2, sample/2, permutations/1]).
5
+ -export_type([continue_or_stop/1, sorting/0]).
6
+
7
+ -if(?OTP_RELEASE >= 27).
8
+ -define(MODULEDOC(Str), -moduledoc(Str)).
9
+ -define(DOC(Str), -doc(Str)).
10
+ -else.
11
+ -define(MODULEDOC(Str), -compile([])).
12
+ -define(DOC(Str), -compile([])).
13
+ -endif.
14
+
15
+ ?MODULEDOC(
16
+ " Lists are an ordered sequence of elements and are one of the most common\n"
17
+ " data types in Gleam.\n"
18
+ "\n"
19
+ " New elements can be added and removed from the front of a list in\n"
20
+ " constant time, while adding and removing from the end requires traversing\n"
21
+ " and copying the whole list, so keep this in mind when designing your\n"
22
+ " programs.\n"
23
+ "\n"
24
+ " There is a dedicated syntax for prefixing to a list:\n"
25
+ "\n"
26
+ " ```gleam\n"
27
+ " let new_list = [1, 2, ..existing_list]\n"
28
+ " ```\n"
29
+ "\n"
30
+ " And a matching syntax for getting the first elements of a list:\n"
31
+ "\n"
32
+ " ```gleam\n"
33
+ " case list {\n"
34
+ " [first_element, ..rest] -> first_element\n"
35
+ " _ -> \"this pattern matches when the list is empty\"\n"
36
+ " }\n"
37
+ " ```\n"
38
+ "\n"
39
+ ).
40
+
41
+ -type continue_or_stop(AAE) :: {continue, AAE} | {stop, AAE}.
42
+
43
+ -type sorting() :: ascending | descending.
44
+
45
+ -file("src/gleam/list.gleam", 60).
46
+ -spec length_loop(list(any()), integer()) -> integer().
47
+ length_loop(List, Count) ->
48
+ case List of
49
+ [_ | List@1] ->
50
+ length_loop(List@1, Count + 1);
51
+
52
+ [] ->
53
+ Count
54
+ end.
55
+
56
+ -file("src/gleam/list.gleam", 56).
57
+ ?DOC(
58
+ " Counts the number of elements in a given list.\n"
59
+ "\n"
60
+ " This function has to traverse the list to determine the number of elements,\n"
61
+ " so it runs in linear time.\n"
62
+ "\n"
63
+ " This function is natively implemented by the virtual machine and is highly\n"
64
+ " optimised.\n"
65
+ "\n"
66
+ " ## Examples\n"
67
+ "\n"
68
+ " ```gleam\n"
69
+ " length([])\n"
70
+ " // -> 0\n"
71
+ " ```\n"
72
+ "\n"
73
+ " ```gleam\n"
74
+ " length([1])\n"
75
+ " // -> 1\n"
76
+ " ```\n"
77
+ "\n"
78
+ " ```gleam\n"
79
+ " length([1, 2])\n"
80
+ " // -> 2\n"
81
+ " ```\n"
82
+ ).
83
+ -spec length(list(any())) -> integer().
84
+ length(List) ->
85
+ erlang:length(List).
86
+
87
+ -file("src/gleam/list.gleam", 93).
88
+ -spec count_loop(list(AAL), fun((AAL) -> boolean()), integer()) -> integer().
89
+ count_loop(List, Predicate, Acc) ->
90
+ case List of
91
+ [] ->
92
+ Acc;
93
+
94
+ [First | Rest] ->
95
+ case Predicate(First) of
96
+ true ->
97
+ count_loop(Rest, Predicate, Acc + 1);
98
+
99
+ false ->
100
+ count_loop(Rest, Predicate, Acc)
101
+ end
102
+ end.
103
+
104
+ -file("src/gleam/list.gleam", 89).
105
+ ?DOC(
106
+ " Counts the number of elements in a given list satisfying a given predicate.\n"
107
+ "\n"
108
+ " This function has to traverse the list to determine the number of elements,\n"
109
+ " so it runs in linear time.\n"
110
+ "\n"
111
+ " ## Examples\n"
112
+ "\n"
113
+ " ```gleam\n"
114
+ " count([], fn(a) { a > 0 })\n"
115
+ " // -> 0\n"
116
+ " ```\n"
117
+ "\n"
118
+ " ```gleam\n"
119
+ " count([1], fn(a) { a > 0 })\n"
120
+ " // -> 1\n"
121
+ " ```\n"
122
+ "\n"
123
+ " ```gleam\n"
124
+ " count([1, 2, 3], int.is_odd)\n"
125
+ " // -> 2\n"
126
+ " ```\n"
127
+ ).
128
+ -spec count(list(AAJ), fun((AAJ) -> boolean())) -> integer().
129
+ count(List, Predicate) ->
130
+ count_loop(List, Predicate, 0).
131
+
132
+ -file("src/gleam/list.gleam", 131).
133
+ ?DOC(
134
+ " Creates a new list from a given list containing the same elements but in the\n"
135
+ " opposite order.\n"
136
+ "\n"
137
+ " This function has to traverse the list to create the new reversed list, so\n"
138
+ " it runs in linear time.\n"
139
+ "\n"
140
+ " This function is natively implemented by the virtual machine and is highly\n"
141
+ " optimised.\n"
142
+ "\n"
143
+ " ## Examples\n"
144
+ "\n"
145
+ " ```gleam\n"
146
+ " reverse([])\n"
147
+ " // -> []\n"
148
+ " ```\n"
149
+ "\n"
150
+ " ```gleam\n"
151
+ " reverse([1])\n"
152
+ " // -> [1]\n"
153
+ " ```\n"
154
+ "\n"
155
+ " ```gleam\n"
156
+ " reverse([1, 2])\n"
157
+ " // -> [2, 1]\n"
158
+ " ```\n"
159
+ ).
160
+ -spec reverse(list(AAN)) -> list(AAN).
161
+ reverse(List) ->
162
+ lists:reverse(List).
163
+
164
+ -file("src/gleam/list.gleam", 168).
165
+ ?DOC(
166
+ " Determines whether or not the list is empty.\n"
167
+ "\n"
168
+ " This function runs in constant time.\n"
169
+ "\n"
170
+ " ## Examples\n"
171
+ "\n"
172
+ " ```gleam\n"
173
+ " is_empty([])\n"
174
+ " // -> True\n"
175
+ " ```\n"
176
+ "\n"
177
+ " ```gleam\n"
178
+ " is_empty([1])\n"
179
+ " // -> False\n"
180
+ " ```\n"
181
+ "\n"
182
+ " ```gleam\n"
183
+ " is_empty([1, 1])\n"
184
+ " // -> False\n"
185
+ " ```\n"
186
+ ).
187
+ -spec is_empty(list(any())) -> boolean().
188
+ is_empty(List) ->
189
+ List =:= [].
190
+
191
+ -file("src/gleam/list.gleam", 204).
192
+ ?DOC(
193
+ " Determines whether or not a given element exists within a given list.\n"
194
+ "\n"
195
+ " This function traverses the list to find the element, so it runs in linear\n"
196
+ " time.\n"
197
+ "\n"
198
+ " ## Examples\n"
199
+ "\n"
200
+ " ```gleam\n"
201
+ " [] |> contains(any: 0)\n"
202
+ " // -> False\n"
203
+ " ```\n"
204
+ "\n"
205
+ " ```gleam\n"
206
+ " [0] |> contains(any: 0)\n"
207
+ " // -> True\n"
208
+ " ```\n"
209
+ "\n"
210
+ " ```gleam\n"
211
+ " [1] |> contains(any: 0)\n"
212
+ " // -> False\n"
213
+ " ```\n"
214
+ "\n"
215
+ " ```gleam\n"
216
+ " [1, 1] |> contains(any: 0)\n"
217
+ " // -> False\n"
218
+ " ```\n"
219
+ "\n"
220
+ " ```gleam\n"
221
+ " [1, 0] |> contains(any: 0)\n"
222
+ " // -> True\n"
223
+ " ```\n"
224
+ ).
225
+ -spec contains(list(AAW), AAW) -> boolean().
226
+ contains(List, Elem) ->
227
+ case List of
228
+ [] ->
229
+ false;
230
+
231
+ [First | _] when First =:= Elem ->
232
+ true;
233
+
234
+ [_ | Rest] ->
235
+ contains(Rest, Elem)
236
+ end.
237
+
238
+ -file("src/gleam/list.gleam", 231).
239
+ ?DOC(
240
+ " Gets the first element from the start of the list, if there is one.\n"
241
+ "\n"
242
+ " ## Examples\n"
243
+ "\n"
244
+ " ```gleam\n"
245
+ " first([])\n"
246
+ " // -> Error(Nil)\n"
247
+ " ```\n"
248
+ "\n"
249
+ " ```gleam\n"
250
+ " first([0])\n"
251
+ " // -> Ok(0)\n"
252
+ " ```\n"
253
+ "\n"
254
+ " ```gleam\n"
255
+ " first([1, 2])\n"
256
+ " // -> Ok(1)\n"
257
+ " ```\n"
258
+ ).
259
+ -spec first(list(AAY)) -> {ok, AAY} | {error, nil}.
260
+ first(List) ->
261
+ case List of
262
+ [] ->
263
+ {error, nil};
264
+
265
+ [First | _] ->
266
+ {ok, First}
267
+ end.
268
+
269
+ -file("src/gleam/list.gleam", 260).
270
+ ?DOC(
271
+ " Returns the list minus the first element. If the list is empty, `Error(Nil)` is\n"
272
+ " returned.\n"
273
+ "\n"
274
+ " This function runs in constant time and does not make a copy of the list.\n"
275
+ "\n"
276
+ " ## Examples\n"
277
+ "\n"
278
+ " ```gleam\n"
279
+ " rest([])\n"
280
+ " // -> Error(Nil)\n"
281
+ " ```\n"
282
+ "\n"
283
+ " ```gleam\n"
284
+ " rest([0])\n"
285
+ " // -> Ok([])\n"
286
+ " ```\n"
287
+ "\n"
288
+ " ```gleam\n"
289
+ " rest([1, 2])\n"
290
+ " // -> Ok([2])\n"
291
+ " ```\n"
292
+ ).
293
+ -spec rest(list(ABC)) -> {ok, list(ABC)} | {error, nil}.
294
+ rest(List) ->
295
+ case List of
296
+ [] ->
297
+ {error, nil};
298
+
299
+ [_ | Rest] ->
300
+ {ok, Rest}
301
+ end.
302
+
303
+ -file("src/gleam/list.gleam", 298).
304
+ ?DOC(
305
+ " Groups the elements from the given list by the given key function.\n"
306
+ "\n"
307
+ " Does not preserve the initial value order.\n"
308
+ "\n"
309
+ " ## Examples\n"
310
+ "\n"
311
+ " ```gleam\n"
312
+ " import gleam/dict\n"
313
+ "\n"
314
+ " [Ok(3), Error(\"Wrong\"), Ok(200), Ok(73)]\n"
315
+ " |> group(by: fn(i) {\n"
316
+ " case i {\n"
317
+ " Ok(_) -> \"Successful\"\n"
318
+ " Error(_) -> \"Failed\"\n"
319
+ " }\n"
320
+ " })\n"
321
+ " |> dict.to_list\n"
322
+ " // -> [\n"
323
+ " // #(\"Failed\", [Error(\"Wrong\")]),\n"
324
+ " // #(\"Successful\", [Ok(73), Ok(200), Ok(3)])\n"
325
+ " // ]\n"
326
+ " ```\n"
327
+ "\n"
328
+ " ```gleam\n"
329
+ " import gleam/dict\n"
330
+ "\n"
331
+ " group([1,2,3,4,5], by: fn(i) { i - i / 3 * 3 })\n"
332
+ " |> dict.to_list\n"
333
+ " // -> [#(0, [3]), #(1, [4, 1]), #(2, [5, 2])]\n"
334
+ " ```\n"
335
+ ).
336
+ -spec group(list(ABH), fun((ABH) -> ABJ)) -> gleam@dict:dict(ABJ, list(ABH)).
337
+ group(List, Key) ->
338
+ gleam@dict:group(Key, List).
339
+
340
+ -file("src/gleam/list.gleam", 321).
341
+ -spec filter_loop(list(ABQ), fun((ABQ) -> boolean()), list(ABQ)) -> list(ABQ).
342
+ filter_loop(List, Fun, Acc) ->
343
+ case List of
344
+ [] ->
345
+ lists:reverse(Acc);
346
+
347
+ [First | Rest] ->
348
+ New_acc = case Fun(First) of
349
+ true ->
350
+ [First | Acc];
351
+
352
+ false ->
353
+ Acc
354
+ end,
355
+ filter_loop(Rest, Fun, New_acc)
356
+ end.
357
+
358
+ -file("src/gleam/list.gleam", 317).
359
+ ?DOC(
360
+ " Returns a new list containing only the elements from the first list for\n"
361
+ " which the given functions returns `True`.\n"
362
+ "\n"
363
+ " ## Examples\n"
364
+ "\n"
365
+ " ```gleam\n"
366
+ " filter([2, 4, 6, 1], fn(x) { x > 2 })\n"
367
+ " // -> [4, 6]\n"
368
+ " ```\n"
369
+ "\n"
370
+ " ```gleam\n"
371
+ " filter([2, 4, 6, 1], fn(x) { x > 6 })\n"
372
+ " // -> []\n"
373
+ " ```\n"
374
+ ).
375
+ -spec filter(list(ABN), fun((ABN) -> boolean())) -> list(ABN).
376
+ filter(List, Predicate) ->
377
+ filter_loop(List, Predicate, []).
378
+
379
+ -file("src/gleam/list.gleam", 353).
380
+ -spec filter_map_loop(
381
+ list(ACB),
382
+ fun((ACB) -> {ok, ACD} | {error, any()}),
383
+ list(ACD)
384
+ ) -> list(ACD).
385
+ filter_map_loop(List, Fun, Acc) ->
386
+ case List of
387
+ [] ->
388
+ lists:reverse(Acc);
389
+
390
+ [First | Rest] ->
391
+ New_acc = case Fun(First) of
392
+ {ok, First@1} ->
393
+ [First@1 | Acc];
394
+
395
+ {error, _} ->
396
+ Acc
397
+ end,
398
+ filter_map_loop(Rest, Fun, New_acc)
399
+ end.
400
+
401
+ -file("src/gleam/list.gleam", 349).
402
+ ?DOC(
403
+ " Returns a new list containing only the elements from the first list for\n"
404
+ " which the given functions returns `Ok(_)`.\n"
405
+ "\n"
406
+ " ## Examples\n"
407
+ "\n"
408
+ " ```gleam\n"
409
+ " filter_map([2, 4, 6, 1], Error)\n"
410
+ " // -> []\n"
411
+ " ```\n"
412
+ "\n"
413
+ " ```gleam\n"
414
+ " filter_map([2, 4, 6, 1], fn(x) { Ok(x + 1) })\n"
415
+ " // -> [3, 5, 7, 2]\n"
416
+ " ```\n"
417
+ ).
418
+ -spec filter_map(list(ABU), fun((ABU) -> {ok, ABW} | {error, any()})) -> list(ABW).
419
+ filter_map(List, Fun) ->
420
+ filter_map_loop(List, Fun, []).
421
+
422
+ -file("src/gleam/list.gleam", 383).
423
+ -spec map_loop(list(ACN), fun((ACN) -> ACP), list(ACP)) -> list(ACP).
424
+ map_loop(List, Fun, Acc) ->
425
+ case List of
426
+ [] ->
427
+ lists:reverse(Acc);
428
+
429
+ [First | Rest] ->
430
+ map_loop(Rest, Fun, [Fun(First) | Acc])
431
+ end.
432
+
433
+ -file("src/gleam/list.gleam", 379).
434
+ ?DOC(
435
+ " Returns a new list containing the results of applying the supplied function to each element.\n"
436
+ "\n"
437
+ " ## Examples\n"
438
+ "\n"
439
+ " ```gleam\n"
440
+ " map([2, 4, 6], fn(x) { x * 2 })\n"
441
+ " // -> [4, 8, 12]\n"
442
+ " ```\n"
443
+ ).
444
+ -spec map(list(ACJ), fun((ACJ) -> ACL)) -> list(ACL).
445
+ map(List, Fun) ->
446
+ map_loop(List, Fun, []).
447
+
448
+ -file("src/gleam/list.gleam", 410).
449
+ -spec map2_loop(list(ACY), list(ADA), fun((ACY, ADA) -> ADC), list(ADC)) -> list(ADC).
450
+ map2_loop(List1, List2, Fun, Acc) ->
451
+ case {List1, List2} of
452
+ {[], _} ->
453
+ lists:reverse(Acc);
454
+
455
+ {_, []} ->
456
+ lists:reverse(Acc);
457
+
458
+ {[A | As_], [B | Bs]} ->
459
+ map2_loop(As_, Bs, Fun, [Fun(A, B) | Acc])
460
+ end.
461
+
462
+ -file("src/gleam/list.gleam", 406).
463
+ ?DOC(
464
+ " Combines two lists into a single list using the given function.\n"
465
+ "\n"
466
+ " If a list is longer than the other, the extra elements are dropped.\n"
467
+ "\n"
468
+ " ## Examples\n"
469
+ "\n"
470
+ " ```gleam\n"
471
+ " map2([1, 2, 3], [4, 5, 6], fn(x, y) { x + y })\n"
472
+ " // -> [5, 7, 9]\n"
473
+ " ```\n"
474
+ "\n"
475
+ " ```gleam\n"
476
+ " map2([1, 2], [\"a\", \"b\", \"c\"], fn(i, x) { #(i, x) })\n"
477
+ " // -> [#(1, \"a\"), #(2, \"b\")]\n"
478
+ " ```\n"
479
+ ).
480
+ -spec map2(list(ACS), list(ACU), fun((ACS, ACU) -> ACW)) -> list(ACW).
481
+ map2(List1, List2, Fun) ->
482
+ map2_loop(List1, List2, Fun, []).
483
+
484
+ -file("src/gleam/list.gleam", 443).
485
+ -spec map_fold_loop(list(ADK), fun((ADM, ADK) -> {ADM, ADN}), ADM, list(ADN)) -> {ADM,
486
+ list(ADN)}.
487
+ map_fold_loop(List, Fun, Acc, List_acc) ->
488
+ case List of
489
+ [] ->
490
+ {Acc, lists:reverse(List_acc)};
491
+
492
+ [First | Rest] ->
493
+ {Acc@1, First@1} = Fun(Acc, First),
494
+ map_fold_loop(Rest, Fun, Acc@1, [First@1 | List_acc])
495
+ end.
496
+
497
+ -file("src/gleam/list.gleam", 435).
498
+ ?DOC(
499
+ " Similar to `map` but also lets you pass around an accumulated value.\n"
500
+ "\n"
501
+ " ## Examples\n"
502
+ "\n"
503
+ " ```gleam\n"
504
+ " map_fold(\n"
505
+ " over: [1, 2, 3],\n"
506
+ " from: 100,\n"
507
+ " with: fn(memo, i) { #(memo + i, i * 2) }\n"
508
+ " )\n"
509
+ " // -> #(106, [2, 4, 6])\n"
510
+ " ```\n"
511
+ ).
512
+ -spec map_fold(list(ADF), ADH, fun((ADH, ADF) -> {ADH, ADI})) -> {ADH,
513
+ list(ADI)}.
514
+ map_fold(List, Initial, Fun) ->
515
+ map_fold_loop(List, Fun, Initial, []).
516
+
517
+ -file("src/gleam/list.gleam", 475).
518
+ -spec index_map_loop(
519
+ list(ADU),
520
+ fun((ADU, integer()) -> ADW),
521
+ integer(),
522
+ list(ADW)
523
+ ) -> list(ADW).
524
+ index_map_loop(List, Fun, Index, Acc) ->
525
+ case List of
526
+ [] ->
527
+ lists:reverse(Acc);
528
+
529
+ [First | Rest] ->
530
+ Acc@1 = [Fun(First, Index) | Acc],
531
+ index_map_loop(Rest, Fun, Index + 1, Acc@1)
532
+ end.
533
+
534
+ -file("src/gleam/list.gleam", 471).
535
+ ?DOC(
536
+ " Similar to `map`, but the supplied function will also be passed the index\n"
537
+ " of the element being mapped as an additional argument.\n"
538
+ "\n"
539
+ " The index starts at 0, so the first element is 0, the second is 1, and so\n"
540
+ " on.\n"
541
+ "\n"
542
+ " ## Examples\n"
543
+ "\n"
544
+ " ```gleam\n"
545
+ " index_map([\"a\", \"b\"], fn(x, i) { #(i, x) })\n"
546
+ " // -> [#(0, \"a\"), #(1, \"b\")]\n"
547
+ " ```\n"
548
+ ).
549
+ -spec index_map(list(ADQ), fun((ADQ, integer()) -> ADS)) -> list(ADS).
550
+ index_map(List, Fun) ->
551
+ index_map_loop(List, Fun, 0, []).
552
+
553
+ -file("src/gleam/list.gleam", 529).
554
+ -spec try_map_loop(list(AEI), fun((AEI) -> {ok, AEK} | {error, AEL}), list(AEK)) -> {ok,
555
+ list(AEK)} |
556
+ {error, AEL}.
557
+ try_map_loop(List, Fun, Acc) ->
558
+ case List of
559
+ [] ->
560
+ {ok, lists:reverse(Acc)};
561
+
562
+ [First | Rest] ->
563
+ case Fun(First) of
564
+ {ok, First@1} ->
565
+ try_map_loop(Rest, Fun, [First@1 | Acc]);
566
+
567
+ {error, Error} ->
568
+ {error, Error}
569
+ end
570
+ end.
571
+
572
+ -file("src/gleam/list.gleam", 522).
573
+ ?DOC(
574
+ " Takes a function that returns a `Result` and applies it to each element in a\n"
575
+ " given list in turn.\n"
576
+ "\n"
577
+ " If the function returns `Ok(new_value)` for all elements in the list then a\n"
578
+ " list of the new values is returned.\n"
579
+ "\n"
580
+ " If the function returns `Error(reason)` for any of the elements then it is\n"
581
+ " returned immediately. None of the elements in the list are processed after\n"
582
+ " one returns an `Error`.\n"
583
+ "\n"
584
+ " ## Examples\n"
585
+ "\n"
586
+ " ```gleam\n"
587
+ " try_map([1, 2, 3], fn(x) { Ok(x + 2) })\n"
588
+ " // -> Ok([3, 4, 5])\n"
589
+ " ```\n"
590
+ "\n"
591
+ " ```gleam\n"
592
+ " try_map([1, 2, 3], fn(_) { Error(0) })\n"
593
+ " // -> Error(0)\n"
594
+ " ```\n"
595
+ "\n"
596
+ " ```gleam\n"
597
+ " try_map([[1], [2, 3]], first)\n"
598
+ " // -> Ok([1, 2])\n"
599
+ " ```\n"
600
+ "\n"
601
+ " ```gleam\n"
602
+ " try_map([[1], [], [2]], first)\n"
603
+ " // -> Error(Nil)\n"
604
+ " ```\n"
605
+ ).
606
+ -spec try_map(list(ADZ), fun((ADZ) -> {ok, AEB} | {error, AEC})) -> {ok,
607
+ list(AEB)} |
608
+ {error, AEC}.
609
+ try_map(List, Fun) ->
610
+ try_map_loop(List, Fun, []).
611
+
612
+ -file("src/gleam/list.gleam", 564).
613
+ ?DOC(
614
+ " Returns a list that is the given list with up to the given number of\n"
615
+ " elements removed from the front of the list.\n"
616
+ "\n"
617
+ " If the list has less than the number of elements an empty list is\n"
618
+ " returned.\n"
619
+ "\n"
620
+ " This function runs in linear time but does not copy the list.\n"
621
+ "\n"
622
+ " ## Examples\n"
623
+ "\n"
624
+ " ```gleam\n"
625
+ " drop([1, 2, 3, 4], 2)\n"
626
+ " // -> [3, 4]\n"
627
+ " ```\n"
628
+ "\n"
629
+ " ```gleam\n"
630
+ " drop([1, 2, 3, 4], 9)\n"
631
+ " // -> []\n"
632
+ " ```\n"
633
+ ).
634
+ -spec drop(list(AES), integer()) -> list(AES).
635
+ drop(List, N) ->
636
+ case N =< 0 of
637
+ true ->
638
+ List;
639
+
640
+ false ->
641
+ case List of
642
+ [] ->
643
+ [];
644
+
645
+ [_ | Rest] ->
646
+ drop(Rest, N - 1)
647
+ end
648
+ end.
649
+
650
+ -file("src/gleam/list.gleam", 599).
651
+ -spec take_loop(list(AEY), integer(), list(AEY)) -> list(AEY).
652
+ take_loop(List, N, Acc) ->
653
+ case N =< 0 of
654
+ true ->
655
+ lists:reverse(Acc);
656
+
657
+ false ->
658
+ case List of
659
+ [] ->
660
+ lists:reverse(Acc);
661
+
662
+ [First | Rest] ->
663
+ take_loop(Rest, N - 1, [First | Acc])
664
+ end
665
+ end.
666
+
667
+ -file("src/gleam/list.gleam", 595).
668
+ ?DOC(
669
+ " Returns a list containing the first given number of elements from the given\n"
670
+ " list.\n"
671
+ "\n"
672
+ " If the list has less than the number of elements then the full list is\n"
673
+ " returned.\n"
674
+ "\n"
675
+ " This function runs in linear time.\n"
676
+ "\n"
677
+ " ## Examples\n"
678
+ "\n"
679
+ " ```gleam\n"
680
+ " take([1, 2, 3, 4], 2)\n"
681
+ " // -> [1, 2]\n"
682
+ " ```\n"
683
+ "\n"
684
+ " ```gleam\n"
685
+ " take([1, 2, 3, 4], 9)\n"
686
+ " // -> [1, 2, 3, 4]\n"
687
+ " ```\n"
688
+ ).
689
+ -spec take(list(AEV), integer()) -> list(AEV).
690
+ take(List, N) ->
691
+ take_loop(List, N, []).
692
+
693
+ -file("src/gleam/list.gleam", 619).
694
+ ?DOC(
695
+ " Returns a new empty list.\n"
696
+ "\n"
697
+ " ## Examples\n"
698
+ "\n"
699
+ " ```gleam\n"
700
+ " new()\n"
701
+ " // -> []\n"
702
+ " ```\n"
703
+ ).
704
+ -spec new() -> list(any()).
705
+ new() ->
706
+ [].
707
+
708
+ -file("src/gleam/list.gleam", 639).
709
+ ?DOC(
710
+ " Returns the given item wrapped in a list.\n"
711
+ "\n"
712
+ " ## Examples\n"
713
+ "\n"
714
+ " ```gleam\n"
715
+ " wrap(1)\n"
716
+ " // -> [1]\n"
717
+ "\n"
718
+ " wrap([\"a\", \"b\", \"c\"])\n"
719
+ " // -> [[\"a\", \"b\", \"c\"]]\n"
720
+ "\n"
721
+ " wrap([[]])\n"
722
+ " // -> [[[]]]\n"
723
+ " ```\n"
724
+ ).
725
+ -spec wrap(AFE) -> list(AFE).
726
+ wrap(Item) ->
727
+ [Item].
728
+
729
+ -file("src/gleam/list.gleam", 660).
730
+ -spec append_loop(list(AFK), list(AFK)) -> list(AFK).
731
+ append_loop(First, Second) ->
732
+ case First of
733
+ [] ->
734
+ Second;
735
+
736
+ [First@1 | Rest] ->
737
+ append_loop(Rest, [First@1 | Second])
738
+ end.
739
+
740
+ -file("src/gleam/list.gleam", 656).
741
+ ?DOC(
742
+ " Joins one list onto the end of another.\n"
743
+ "\n"
744
+ " This function runs in linear time, and it traverses and copies the first\n"
745
+ " list.\n"
746
+ "\n"
747
+ " ## Examples\n"
748
+ "\n"
749
+ " ```gleam\n"
750
+ " append([1, 2], [3])\n"
751
+ " // -> [1, 2, 3]\n"
752
+ " ```\n"
753
+ ).
754
+ -spec append(list(AFG), list(AFG)) -> list(AFG).
755
+ append(First, Second) ->
756
+ lists:append(First, Second).
757
+
758
+ -file("src/gleam/list.gleam", 680).
759
+ ?DOC(
760
+ " Prefixes an item to a list. This can also be done using the dedicated\n"
761
+ " syntax instead.\n"
762
+ "\n"
763
+ " ```gleam\n"
764
+ " let existing_list = [2, 3, 4]\n"
765
+ "\n"
766
+ " [1, ..existing_list]\n"
767
+ " // -> [1, 2, 3, 4]\n"
768
+ "\n"
769
+ " prepend(to: existing_list, this: 1)\n"
770
+ " // -> [1, 2, 3, 4]\n"
771
+ " ```\n"
772
+ ).
773
+ -spec prepend(list(AFO), AFO) -> list(AFO).
774
+ prepend(List, Item) ->
775
+ [Item | List].
776
+
777
+ -file("src/gleam/list.gleam", 701).
778
+ -spec flatten_loop(list(list(AFV)), list(AFV)) -> list(AFV).
779
+ flatten_loop(Lists, Acc) ->
780
+ case Lists of
781
+ [] ->
782
+ lists:reverse(Acc);
783
+
784
+ [List | Further_lists] ->
785
+ flatten_loop(Further_lists, lists:reverse(List, Acc))
786
+ end.
787
+
788
+ -file("src/gleam/list.gleam", 697).
789
+ ?DOC(
790
+ " Joins a list of lists into a single list.\n"
791
+ "\n"
792
+ " This function traverses all elements twice on the JavaScript target.\n"
793
+ " This function traverses all elements once on the Erlang target.\n"
794
+ "\n"
795
+ " ## Examples\n"
796
+ "\n"
797
+ " ```gleam\n"
798
+ " flatten([[1], [2, 3], []])\n"
799
+ " // -> [1, 2, 3]\n"
800
+ " ```\n"
801
+ ).
802
+ -spec flatten(list(list(AFR))) -> list(AFR).
803
+ flatten(Lists) ->
804
+ lists:append(Lists).
805
+
806
+ -file("src/gleam/list.gleam", 718).
807
+ ?DOC(
808
+ " Maps the list with the given function into a list of lists, and then flattens it.\n"
809
+ "\n"
810
+ " ## Examples\n"
811
+ "\n"
812
+ " ```gleam\n"
813
+ " flat_map([2, 4, 6], fn(x) { [x, x + 1] })\n"
814
+ " // -> [2, 3, 4, 5, 6, 7]\n"
815
+ " ```\n"
816
+ ).
817
+ -spec flat_map(list(AGA), fun((AGA) -> list(AGC))) -> list(AGC).
818
+ flat_map(List, Fun) ->
819
+ lists:append(map(List, Fun)).
820
+
821
+ -file("src/gleam/list.gleam", 730).
822
+ ?DOC(
823
+ " Reduces a list of elements into a single value by calling a given function\n"
824
+ " on each element, going from left to right.\n"
825
+ "\n"
826
+ " `fold([1, 2, 3], 0, add)` is the equivalent of\n"
827
+ " `add(add(add(0, 1), 2), 3)`.\n"
828
+ "\n"
829
+ " This function runs in linear time.\n"
830
+ ).
831
+ -spec fold(list(AGF), AGH, fun((AGH, AGF) -> AGH)) -> AGH.
832
+ fold(List, Initial, Fun) ->
833
+ case List of
834
+ [] ->
835
+ Initial;
836
+
837
+ [First | Rest] ->
838
+ fold(Rest, Fun(Initial, First), Fun)
839
+ end.
840
+
841
+ -file("src/gleam/list.gleam", 752).
842
+ ?DOC(
843
+ " Reduces a list of elements into a single value by calling a given function\n"
844
+ " on each element, going from right to left.\n"
845
+ "\n"
846
+ " `fold_right([1, 2, 3], 0, add)` is the equivalent of\n"
847
+ " `add(add(add(0, 3), 2), 1)`.\n"
848
+ "\n"
849
+ " This function runs in linear time.\n"
850
+ "\n"
851
+ " Unlike `fold` this function is not tail recursive. Where possible use\n"
852
+ " `fold` instead as it will use less memory.\n"
853
+ ).
854
+ -spec fold_right(list(AGI), AGK, fun((AGK, AGI) -> AGK)) -> AGK.
855
+ fold_right(List, Initial, Fun) ->
856
+ case List of
857
+ [] ->
858
+ Initial;
859
+
860
+ [First | Rest] ->
861
+ Fun(fold_right(Rest, Initial, Fun), First)
862
+ end.
863
+
864
+ -file("src/gleam/list.gleam", 789).
865
+ -spec index_fold_loop(
866
+ list(AGO),
867
+ AGQ,
868
+ fun((AGQ, AGO, integer()) -> AGQ),
869
+ integer()
870
+ ) -> AGQ.
871
+ index_fold_loop(Over, Acc, With, Index) ->
872
+ case Over of
873
+ [] ->
874
+ Acc;
875
+
876
+ [First | Rest] ->
877
+ index_fold_loop(Rest, With(Acc, First, Index), With, Index + 1)
878
+ end.
879
+
880
+ -file("src/gleam/list.gleam", 781).
881
+ ?DOC(
882
+ " Like `fold` but the folding function also receives the index of the current element.\n"
883
+ "\n"
884
+ " ## Examples\n"
885
+ "\n"
886
+ " ```gleam\n"
887
+ " [\"a\", \"b\", \"c\"]\n"
888
+ " |> index_fold(\"\", fn(acc, item, index) {\n"
889
+ " acc <> int.to_string(index) <> \":\" <> item <> \" \"\n"
890
+ " })\n"
891
+ " // -> \"0:a 1:b 2:c\"\n"
892
+ " ```\n"
893
+ "\n"
894
+ " ```gleam\n"
895
+ " [10, 20, 30]\n"
896
+ " |> index_fold(0, fn(acc, item, index) { acc + item * index })\n"
897
+ " // -> 80\n"
898
+ " ```\n"
899
+ ).
900
+ -spec index_fold(list(AGL), AGN, fun((AGN, AGL, integer()) -> AGN)) -> AGN.
901
+ index_fold(List, Initial, Fun) ->
902
+ index_fold_loop(List, Initial, Fun, 0).
903
+
904
+ -file("src/gleam/list.gleam", 821).
905
+ ?DOC(
906
+ " A variant of fold that might fail.\n"
907
+ "\n"
908
+ " The folding function should return `Result(accumulator, error)`.\n"
909
+ " If the returned value is `Ok(accumulator)` try_fold will try the next value in the list.\n"
910
+ " If the returned value is `Error(error)` try_fold will stop and return that error.\n"
911
+ "\n"
912
+ " ## Examples\n"
913
+ "\n"
914
+ " ```gleam\n"
915
+ " [1, 2, 3, 4]\n"
916
+ " |> try_fold(0, fn(acc, i) {\n"
917
+ " case i < 3 {\n"
918
+ " True -> Ok(acc + i)\n"
919
+ " False -> Error(Nil)\n"
920
+ " }\n"
921
+ " })\n"
922
+ " // -> Error(Nil)\n"
923
+ " ```\n"
924
+ ).
925
+ -spec try_fold(list(AGR), AGT, fun((AGT, AGR) -> {ok, AGT} | {error, AGU})) -> {ok,
926
+ AGT} |
927
+ {error, AGU}.
928
+ try_fold(List, Initial, Fun) ->
929
+ case List of
930
+ [] ->
931
+ {ok, Initial};
932
+
933
+ [First | Rest] ->
934
+ case Fun(Initial, First) of
935
+ {ok, Result} ->
936
+ try_fold(Rest, Result, Fun);
937
+
938
+ {error, _} = Error ->
939
+ Error
940
+ end
941
+ end.
942
+
943
+ -file("src/gleam/list.gleam", 860).
944
+ ?DOC(
945
+ " A variant of fold that allows to stop folding earlier.\n"
946
+ "\n"
947
+ " The folding function should return `ContinueOrStop(accumulator)`.\n"
948
+ " If the returned value is `Continue(accumulator)` fold_until will try the next value in the list.\n"
949
+ " If the returned value is `Stop(accumulator)` fold_until will stop and return that accumulator.\n"
950
+ "\n"
951
+ " ## Examples\n"
952
+ "\n"
953
+ " ```gleam\n"
954
+ " [1, 2, 3, 4]\n"
955
+ " |> fold_until(0, fn(acc, i) {\n"
956
+ " case i < 3 {\n"
957
+ " True -> Continue(acc + i)\n"
958
+ " False -> Stop(acc)\n"
959
+ " }\n"
960
+ " })\n"
961
+ " // -> 3\n"
962
+ " ```\n"
963
+ ).
964
+ -spec fold_until(list(AGZ), AHB, fun((AHB, AGZ) -> continue_or_stop(AHB))) -> AHB.
965
+ fold_until(List, Initial, Fun) ->
966
+ case List of
967
+ [] ->
968
+ Initial;
969
+
970
+ [First | Rest] ->
971
+ case Fun(Initial, First) of
972
+ {continue, Next_accumulator} ->
973
+ fold_until(Rest, Next_accumulator, Fun);
974
+
975
+ {stop, B} ->
976
+ B
977
+ end
978
+ end.
979
+
980
+ -file("src/gleam/list.gleam", 897).
981
+ ?DOC(
982
+ " Finds the first element in a given list for which the given function returns\n"
983
+ " `True`.\n"
984
+ "\n"
985
+ " Returns `Error(Nil)` if no such element is found.\n"
986
+ "\n"
987
+ " ## Examples\n"
988
+ "\n"
989
+ " ```gleam\n"
990
+ " find([1, 2, 3], fn(x) { x > 2 })\n"
991
+ " // -> Ok(3)\n"
992
+ " ```\n"
993
+ "\n"
994
+ " ```gleam\n"
995
+ " find([1, 2, 3], fn(x) { x > 4 })\n"
996
+ " // -> Error(Nil)\n"
997
+ " ```\n"
998
+ "\n"
999
+ " ```gleam\n"
1000
+ " find([], fn(_) { True })\n"
1001
+ " // -> Error(Nil)\n"
1002
+ " ```\n"
1003
+ ).
1004
+ -spec find(list(AHD), fun((AHD) -> boolean())) -> {ok, AHD} | {error, nil}.
1005
+ find(List, Is_desired) ->
1006
+ case List of
1007
+ [] ->
1008
+ {error, nil};
1009
+
1010
+ [First | Rest] ->
1011
+ case Is_desired(First) of
1012
+ true ->
1013
+ {ok, First};
1014
+
1015
+ false ->
1016
+ find(Rest, Is_desired)
1017
+ end
1018
+ end.
1019
+
1020
+ -file("src/gleam/list.gleam", 933).
1021
+ ?DOC(
1022
+ " Finds the first element in a given list for which the given function returns\n"
1023
+ " `Ok(new_value)`, then returns the wrapped `new_value`.\n"
1024
+ "\n"
1025
+ " Returns `Error(Nil)` if no such element is found.\n"
1026
+ "\n"
1027
+ " ## Examples\n"
1028
+ "\n"
1029
+ " ```gleam\n"
1030
+ " find_map([[], [2], [3]], first)\n"
1031
+ " // -> Ok(2)\n"
1032
+ " ```\n"
1033
+ "\n"
1034
+ " ```gleam\n"
1035
+ " find_map([[], []], first)\n"
1036
+ " // -> Error(Nil)\n"
1037
+ " ```\n"
1038
+ "\n"
1039
+ " ```gleam\n"
1040
+ " find_map([], first)\n"
1041
+ " // -> Error(Nil)\n"
1042
+ " ```\n"
1043
+ ).
1044
+ -spec find_map(list(AHH), fun((AHH) -> {ok, AHJ} | {error, any()})) -> {ok, AHJ} |
1045
+ {error, nil}.
1046
+ find_map(List, Fun) ->
1047
+ case List of
1048
+ [] ->
1049
+ {error, nil};
1050
+
1051
+ [First | Rest] ->
1052
+ case Fun(First) of
1053
+ {ok, First@1} ->
1054
+ {ok, First@1};
1055
+
1056
+ {error, _} ->
1057
+ find_map(Rest, Fun)
1058
+ end
1059
+ end.
1060
+
1061
+ -file("src/gleam/list.gleam", 968).
1062
+ ?DOC(
1063
+ " Returns `True` if the given function returns `True` for all the elements in\n"
1064
+ " the given list. If the function returns `False` for any of the elements it\n"
1065
+ " immediately returns `False` without checking the rest of the list.\n"
1066
+ "\n"
1067
+ " ## Examples\n"
1068
+ "\n"
1069
+ " ```gleam\n"
1070
+ " all([], fn(x) { x > 3 })\n"
1071
+ " // -> True\n"
1072
+ " ```\n"
1073
+ "\n"
1074
+ " ```gleam\n"
1075
+ " all([4, 5], fn(x) { x > 3 })\n"
1076
+ " // -> True\n"
1077
+ " ```\n"
1078
+ "\n"
1079
+ " ```gleam\n"
1080
+ " all([4, 3], fn(x) { x > 3 })\n"
1081
+ " // -> False\n"
1082
+ " ```\n"
1083
+ ).
1084
+ -spec all(list(AHP), fun((AHP) -> boolean())) -> boolean().
1085
+ all(List, Predicate) ->
1086
+ case List of
1087
+ [] ->
1088
+ true;
1089
+
1090
+ [First | Rest] ->
1091
+ case Predicate(First) of
1092
+ true ->
1093
+ all(Rest, Predicate);
1094
+
1095
+ false ->
1096
+ false
1097
+ end
1098
+ end.
1099
+
1100
+ -file("src/gleam/list.gleam", 1005).
1101
+ ?DOC(
1102
+ " Returns `True` if the given function returns `True` for any the elements in\n"
1103
+ " the given list. If the function returns `True` for any of the elements it\n"
1104
+ " immediately returns `True` without checking the rest of the list.\n"
1105
+ "\n"
1106
+ " ## Examples\n"
1107
+ "\n"
1108
+ " ```gleam\n"
1109
+ " any([], fn(x) { x > 3 })\n"
1110
+ " // -> False\n"
1111
+ " ```\n"
1112
+ "\n"
1113
+ " ```gleam\n"
1114
+ " any([4, 5], fn(x) { x > 3 })\n"
1115
+ " // -> True\n"
1116
+ " ```\n"
1117
+ "\n"
1118
+ " ```gleam\n"
1119
+ " any([4, 3], fn(x) { x > 4 })\n"
1120
+ " // -> False\n"
1121
+ " ```\n"
1122
+ "\n"
1123
+ " ```gleam\n"
1124
+ " any([3, 4], fn(x) { x > 3 })\n"
1125
+ " // -> True\n"
1126
+ " ```\n"
1127
+ ).
1128
+ -spec any(list(AHR), fun((AHR) -> boolean())) -> boolean().
1129
+ any(List, Predicate) ->
1130
+ case List of
1131
+ [] ->
1132
+ false;
1133
+
1134
+ [First | Rest] ->
1135
+ case Predicate(First) of
1136
+ true ->
1137
+ true;
1138
+
1139
+ false ->
1140
+ any(Rest, Predicate)
1141
+ end
1142
+ end.
1143
+
1144
+ -file("src/gleam/list.gleam", 1047).
1145
+ -spec zip_loop(list(AHY), list(AIA), list({AHY, AIA})) -> list({AHY, AIA}).
1146
+ zip_loop(One, Other, Acc) ->
1147
+ case {One, Other} of
1148
+ {[First_one | Rest_one], [First_other | Rest_other]} ->
1149
+ zip_loop(Rest_one, Rest_other, [{First_one, First_other} | Acc]);
1150
+
1151
+ {_, _} ->
1152
+ lists:reverse(Acc)
1153
+ end.
1154
+
1155
+ -file("src/gleam/list.gleam", 1043).
1156
+ ?DOC(
1157
+ " Takes two lists and returns a single list of 2-element tuples.\n"
1158
+ "\n"
1159
+ " If one of the lists is longer than the other, the remaining elements from\n"
1160
+ " the longer list are not used.\n"
1161
+ "\n"
1162
+ " ## Examples\n"
1163
+ "\n"
1164
+ " ```gleam\n"
1165
+ " zip([], [])\n"
1166
+ " // -> []\n"
1167
+ " ```\n"
1168
+ "\n"
1169
+ " ```gleam\n"
1170
+ " zip([1, 2], [3])\n"
1171
+ " // -> [#(1, 3)]\n"
1172
+ " ```\n"
1173
+ "\n"
1174
+ " ```gleam\n"
1175
+ " zip([1], [3, 4])\n"
1176
+ " // -> [#(1, 3)]\n"
1177
+ " ```\n"
1178
+ "\n"
1179
+ " ```gleam\n"
1180
+ " zip([1, 2], [3, 4])\n"
1181
+ " // -> [#(1, 3), #(2, 4)]\n"
1182
+ " ```\n"
1183
+ ).
1184
+ -spec zip(list(AHT), list(AHV)) -> list({AHT, AHV}).
1185
+ zip(List, Other) ->
1186
+ zip_loop(List, Other, []).
1187
+
1188
+ -file("src/gleam/list.gleam", 1088).
1189
+ -spec strict_zip_loop(list(AIL), list(AIN), list({AIL, AIN})) -> {ok,
1190
+ list({AIL, AIN})} |
1191
+ {error, nil}.
1192
+ strict_zip_loop(One, Other, Acc) ->
1193
+ case {One, Other} of
1194
+ {[], []} ->
1195
+ {ok, lists:reverse(Acc)};
1196
+
1197
+ {[], _} ->
1198
+ {error, nil};
1199
+
1200
+ {_, []} ->
1201
+ {error, nil};
1202
+
1203
+ {[First_one | Rest_one], [First_other | Rest_other]} ->
1204
+ strict_zip_loop(
1205
+ Rest_one,
1206
+ Rest_other,
1207
+ [{First_one, First_other} | Acc]
1208
+ )
1209
+ end.
1210
+
1211
+ -file("src/gleam/list.gleam", 1081).
1212
+ ?DOC(
1213
+ " Takes two lists and returns a single list of 2-element tuples.\n"
1214
+ "\n"
1215
+ " If one of the lists is longer than the other, an `Error` is returned.\n"
1216
+ "\n"
1217
+ " ## Examples\n"
1218
+ "\n"
1219
+ " ```gleam\n"
1220
+ " strict_zip([], [])\n"
1221
+ " // -> Ok([])\n"
1222
+ " ```\n"
1223
+ "\n"
1224
+ " ```gleam\n"
1225
+ " strict_zip([1, 2], [3])\n"
1226
+ " // -> Error(Nil)\n"
1227
+ " ```\n"
1228
+ "\n"
1229
+ " ```gleam\n"
1230
+ " strict_zip([1], [3, 4])\n"
1231
+ " // -> Error(Nil)\n"
1232
+ " ```\n"
1233
+ "\n"
1234
+ " ```gleam\n"
1235
+ " strict_zip([1, 2], [3, 4])\n"
1236
+ " // -> Ok([#(1, 3), #(2, 4)])\n"
1237
+ " ```\n"
1238
+ ).
1239
+ -spec strict_zip(list(AIE), list(AIG)) -> {ok, list({AIE, AIG})} | {error, nil}.
1240
+ strict_zip(List, Other) ->
1241
+ strict_zip_loop(List, Other, []).
1242
+
1243
+ -file("src/gleam/list.gleam", 1119).
1244
+ -spec unzip_loop(list({AIY, AIZ}), list(AIY), list(AIZ)) -> {list(AIY),
1245
+ list(AIZ)}.
1246
+ unzip_loop(Input, One, Other) ->
1247
+ case Input of
1248
+ [] ->
1249
+ {lists:reverse(One), lists:reverse(Other)};
1250
+
1251
+ [{First_one, First_other} | Rest] ->
1252
+ unzip_loop(Rest, [First_one | One], [First_other | Other])
1253
+ end.
1254
+
1255
+ -file("src/gleam/list.gleam", 1115).
1256
+ ?DOC(
1257
+ " Takes a single list of 2-element tuples and returns two lists.\n"
1258
+ "\n"
1259
+ " ## Examples\n"
1260
+ "\n"
1261
+ " ```gleam\n"
1262
+ " unzip([#(1, 2), #(3, 4)])\n"
1263
+ " // -> #([1, 3], [2, 4])\n"
1264
+ " ```\n"
1265
+ "\n"
1266
+ " ```gleam\n"
1267
+ " unzip([])\n"
1268
+ " // -> #([], [])\n"
1269
+ " ```\n"
1270
+ ).
1271
+ -spec unzip(list({AIT, AIU})) -> {list(AIT), list(AIU)}.
1272
+ unzip(Input) ->
1273
+ unzip_loop(Input, [], []).
1274
+
1275
+ -file("src/gleam/list.gleam", 1154).
1276
+ -spec intersperse_loop(list(AJI), AJI, list(AJI)) -> list(AJI).
1277
+ intersperse_loop(List, Separator, Acc) ->
1278
+ case List of
1279
+ [] ->
1280
+ lists:reverse(Acc);
1281
+
1282
+ [First | Rest] ->
1283
+ intersperse_loop(Rest, Separator, [First, Separator | Acc])
1284
+ end.
1285
+
1286
+ -file("src/gleam/list.gleam", 1147).
1287
+ ?DOC(
1288
+ " Inserts a given value between each existing element in a given list.\n"
1289
+ "\n"
1290
+ " This function runs in linear time and copies the list.\n"
1291
+ "\n"
1292
+ " ## Examples\n"
1293
+ "\n"
1294
+ " ```gleam\n"
1295
+ " intersperse([1, 1, 1], 2)\n"
1296
+ " // -> [1, 2, 1, 2, 1]\n"
1297
+ " ```\n"
1298
+ "\n"
1299
+ " ```gleam\n"
1300
+ " intersperse([], 2)\n"
1301
+ " // -> []\n"
1302
+ " ```\n"
1303
+ ).
1304
+ -spec intersperse(list(AJF), AJF) -> list(AJF).
1305
+ intersperse(List, Elem) ->
1306
+ case List of
1307
+ [] ->
1308
+ List;
1309
+
1310
+ [_] ->
1311
+ List;
1312
+
1313
+ [First | Rest] ->
1314
+ intersperse_loop(Rest, Elem, [First])
1315
+ end.
1316
+
1317
+ -file("src/gleam/list.gleam", 1177).
1318
+ -spec unique_loop(list(AJP), gleam@dict:dict(AJP, nil), list(AJP)) -> list(AJP).
1319
+ unique_loop(List, Seen, Acc) ->
1320
+ case List of
1321
+ [] ->
1322
+ lists:reverse(Acc);
1323
+
1324
+ [First | Rest] ->
1325
+ case gleam@dict:has_key(Seen, First) of
1326
+ true ->
1327
+ unique_loop(Rest, Seen, Acc);
1328
+
1329
+ false ->
1330
+ unique_loop(
1331
+ Rest,
1332
+ gleam@dict:insert(Seen, First, nil),
1333
+ [First | Acc]
1334
+ )
1335
+ end
1336
+ end.
1337
+
1338
+ -file("src/gleam/list.gleam", 1173).
1339
+ ?DOC(
1340
+ " Removes any duplicate elements from a given list.\n"
1341
+ "\n"
1342
+ " This function returns in loglinear time.\n"
1343
+ "\n"
1344
+ " ## Examples\n"
1345
+ "\n"
1346
+ " ```gleam\n"
1347
+ " unique([1, 1, 1, 4, 7, 3, 3, 4])\n"
1348
+ " // -> [1, 4, 7, 3]\n"
1349
+ " ```\n"
1350
+ ).
1351
+ -spec unique(list(AJM)) -> list(AJM).
1352
+ unique(List) ->
1353
+ unique_loop(List, maps:new(), []).
1354
+
1355
+ -file("src/gleam/list.gleam", 1263).
1356
+ ?DOC(
1357
+ " Given a list it returns slices of it that are locally sorted in ascending\n"
1358
+ " order.\n"
1359
+ "\n"
1360
+ " Imagine you have this list:\n"
1361
+ "\n"
1362
+ " ```\n"
1363
+ " [1, 2, 3, 2, 1, 0]\n"
1364
+ " ^^^^^^^ ^^^^^^^ This is a slice in descending order\n"
1365
+ " |\n"
1366
+ " | This is a slice that is sorted in ascending order\n"
1367
+ " ```\n"
1368
+ "\n"
1369
+ " So the produced result will contain these two slices, each one sorted in\n"
1370
+ " ascending order: `[[1, 2, 3], [0, 1, 2]]`.\n"
1371
+ "\n"
1372
+ " - `growing` is an accumulator with the current slice being grown\n"
1373
+ " - `direction` is the growing direction of the slice being grown, it could\n"
1374
+ " either be ascending or strictly descending\n"
1375
+ " - `prev` is the previous element that needs to be added to the growing slice\n"
1376
+ " it is carried around to check whether we have to keep growing the current\n"
1377
+ " slice or not\n"
1378
+ " - `acc` is the accumulator containing the slices sorted in ascending order\n"
1379
+ ).
1380
+ -spec sequences(
1381
+ list(AJY),
1382
+ fun((AJY, AJY) -> gleam@order:order()),
1383
+ list(AJY),
1384
+ sorting(),
1385
+ AJY,
1386
+ list(list(AJY))
1387
+ ) -> list(list(AJY)).
1388
+ sequences(List, Compare, Growing, Direction, Prev, Acc) ->
1389
+ Growing@1 = [Prev | Growing],
1390
+ case List of
1391
+ [] ->
1392
+ case Direction of
1393
+ ascending ->
1394
+ [lists:reverse(Growing@1) | Acc];
1395
+
1396
+ descending ->
1397
+ [Growing@1 | Acc]
1398
+ end;
1399
+
1400
+ [New | Rest] ->
1401
+ case {Compare(Prev, New), Direction} of
1402
+ {gt, descending} ->
1403
+ sequences(Rest, Compare, Growing@1, Direction, New, Acc);
1404
+
1405
+ {lt, ascending} ->
1406
+ sequences(Rest, Compare, Growing@1, Direction, New, Acc);
1407
+
1408
+ {eq, ascending} ->
1409
+ sequences(Rest, Compare, Growing@1, Direction, New, Acc);
1410
+
1411
+ {gt, ascending} ->
1412
+ Acc@1 = case Direction of
1413
+ ascending ->
1414
+ [lists:reverse(Growing@1) | Acc];
1415
+
1416
+ descending ->
1417
+ [Growing@1 | Acc]
1418
+ end,
1419
+ case Rest of
1420
+ [] ->
1421
+ [[New] | Acc@1];
1422
+
1423
+ [Next | Rest@1] ->
1424
+ Direction@1 = case Compare(New, Next) of
1425
+ lt ->
1426
+ ascending;
1427
+
1428
+ eq ->
1429
+ ascending;
1430
+
1431
+ gt ->
1432
+ descending
1433
+ end,
1434
+ sequences(
1435
+ Rest@1,
1436
+ Compare,
1437
+ [New],
1438
+ Direction@1,
1439
+ Next,
1440
+ Acc@1
1441
+ )
1442
+ end;
1443
+
1444
+ {lt, descending} ->
1445
+ Acc@1 = case Direction of
1446
+ ascending ->
1447
+ [lists:reverse(Growing@1) | Acc];
1448
+
1449
+ descending ->
1450
+ [Growing@1 | Acc]
1451
+ end,
1452
+ case Rest of
1453
+ [] ->
1454
+ [[New] | Acc@1];
1455
+
1456
+ [Next | Rest@1] ->
1457
+ Direction@1 = case Compare(New, Next) of
1458
+ lt ->
1459
+ ascending;
1460
+
1461
+ eq ->
1462
+ ascending;
1463
+
1464
+ gt ->
1465
+ descending
1466
+ end,
1467
+ sequences(
1468
+ Rest@1,
1469
+ Compare,
1470
+ [New],
1471
+ Direction@1,
1472
+ Next,
1473
+ Acc@1
1474
+ )
1475
+ end;
1476
+
1477
+ {eq, descending} ->
1478
+ Acc@1 = case Direction of
1479
+ ascending ->
1480
+ [lists:reverse(Growing@1) | Acc];
1481
+
1482
+ descending ->
1483
+ [Growing@1 | Acc]
1484
+ end,
1485
+ case Rest of
1486
+ [] ->
1487
+ [[New] | Acc@1];
1488
+
1489
+ [Next | Rest@1] ->
1490
+ Direction@1 = case Compare(New, Next) of
1491
+ lt ->
1492
+ ascending;
1493
+
1494
+ eq ->
1495
+ ascending;
1496
+
1497
+ gt ->
1498
+ descending
1499
+ end,
1500
+ sequences(
1501
+ Rest@1,
1502
+ Compare,
1503
+ [New],
1504
+ Direction@1,
1505
+ Next,
1506
+ Acc@1
1507
+ )
1508
+ end
1509
+ end
1510
+ end.
1511
+
1512
+ -file("src/gleam/list.gleam", 1411).
1513
+ ?DOC(
1514
+ " Merges two lists sorted in ascending order into a single list sorted in\n"
1515
+ " descending order according to the given comparator function.\n"
1516
+ "\n"
1517
+ " This reversing of the sort order is not avoidable if we want to implement\n"
1518
+ " merge as a tail recursive function. We could reverse the accumulator before\n"
1519
+ " returning it but that would end up being less efficient; so the merging\n"
1520
+ " algorithm has to play around this.\n"
1521
+ ).
1522
+ -spec merge_ascendings(
1523
+ list(AKV),
1524
+ list(AKV),
1525
+ fun((AKV, AKV) -> gleam@order:order()),
1526
+ list(AKV)
1527
+ ) -> list(AKV).
1528
+ merge_ascendings(List1, List2, Compare, Acc) ->
1529
+ case {List1, List2} of
1530
+ {[], List} ->
1531
+ lists:reverse(List, Acc);
1532
+
1533
+ {List, []} ->
1534
+ lists:reverse(List, Acc);
1535
+
1536
+ {[First1 | Rest1], [First2 | Rest2]} ->
1537
+ case Compare(First1, First2) of
1538
+ lt ->
1539
+ merge_ascendings(Rest1, List2, Compare, [First1 | Acc]);
1540
+
1541
+ gt ->
1542
+ merge_ascendings(List1, Rest2, Compare, [First2 | Acc]);
1543
+
1544
+ eq ->
1545
+ merge_ascendings(List1, Rest2, Compare, [First2 | Acc])
1546
+ end
1547
+ end.
1548
+
1549
+ -file("src/gleam/list.gleam", 1364).
1550
+ ?DOC(
1551
+ " Given a list of ascending lists, it merges adjacent pairs into a single\n"
1552
+ " descending list, halving their number.\n"
1553
+ " It returns a list of the remaining descending lists.\n"
1554
+ ).
1555
+ -spec merge_ascending_pairs(
1556
+ list(list(AKJ)),
1557
+ fun((AKJ, AKJ) -> gleam@order:order()),
1558
+ list(list(AKJ))
1559
+ ) -> list(list(AKJ)).
1560
+ merge_ascending_pairs(Sequences, Compare, Acc) ->
1561
+ case Sequences of
1562
+ [] ->
1563
+ lists:reverse(Acc);
1564
+
1565
+ [Sequence] ->
1566
+ lists:reverse([lists:reverse(Sequence) | Acc]);
1567
+
1568
+ [Ascending1, Ascending2 | Rest] ->
1569
+ Descending = merge_ascendings(Ascending1, Ascending2, Compare, []),
1570
+ merge_ascending_pairs(Rest, Compare, [Descending | Acc])
1571
+ end.
1572
+
1573
+ -file("src/gleam/list.gleam", 1438).
1574
+ ?DOC(
1575
+ " This is exactly the same as merge_ascendings but mirrored: it merges two\n"
1576
+ " lists sorted in descending order into a single list sorted in ascending\n"
1577
+ " order according to the given comparator function.\n"
1578
+ "\n"
1579
+ " This reversing of the sort order is not avoidable if we want to implement\n"
1580
+ " merge as a tail recursive function. We could reverse the accumulator before\n"
1581
+ " returning it but that would end up being less efficient; so the merging\n"
1582
+ " algorithm has to play around this.\n"
1583
+ ).
1584
+ -spec merge_descendings(
1585
+ list(ALA),
1586
+ list(ALA),
1587
+ fun((ALA, ALA) -> gleam@order:order()),
1588
+ list(ALA)
1589
+ ) -> list(ALA).
1590
+ merge_descendings(List1, List2, Compare, Acc) ->
1591
+ case {List1, List2} of
1592
+ {[], List} ->
1593
+ lists:reverse(List, Acc);
1594
+
1595
+ {List, []} ->
1596
+ lists:reverse(List, Acc);
1597
+
1598
+ {[First1 | Rest1], [First2 | Rest2]} ->
1599
+ case Compare(First1, First2) of
1600
+ lt ->
1601
+ merge_descendings(List1, Rest2, Compare, [First2 | Acc]);
1602
+
1603
+ gt ->
1604
+ merge_descendings(Rest1, List2, Compare, [First1 | Acc]);
1605
+
1606
+ eq ->
1607
+ merge_descendings(Rest1, List2, Compare, [First1 | Acc])
1608
+ end
1609
+ end.
1610
+
1611
+ -file("src/gleam/list.gleam", 1386).
1612
+ ?DOC(" This is the same as merge_ascending_pairs but flipped for descending lists.\n").
1613
+ -spec merge_descending_pairs(
1614
+ list(list(AKP)),
1615
+ fun((AKP, AKP) -> gleam@order:order()),
1616
+ list(list(AKP))
1617
+ ) -> list(list(AKP)).
1618
+ merge_descending_pairs(Sequences, Compare, Acc) ->
1619
+ case Sequences of
1620
+ [] ->
1621
+ lists:reverse(Acc);
1622
+
1623
+ [Sequence] ->
1624
+ lists:reverse([lists:reverse(Sequence) | Acc]);
1625
+
1626
+ [Descending1, Descending2 | Rest] ->
1627
+ Ascending = merge_descendings(Descending1, Descending2, Compare, []),
1628
+ merge_descending_pairs(Rest, Compare, [Ascending | Acc])
1629
+ end.
1630
+
1631
+ -file("src/gleam/list.gleam", 1330).
1632
+ ?DOC(
1633
+ " Given some some sorted sequences (assumed to be sorted in `direction`) it\n"
1634
+ " merges them all together until we're left with just a list sorted in\n"
1635
+ " ascending order.\n"
1636
+ ).
1637
+ -spec merge_all(
1638
+ list(list(AKF)),
1639
+ sorting(),
1640
+ fun((AKF, AKF) -> gleam@order:order())
1641
+ ) -> list(AKF).
1642
+ merge_all(Sequences, Direction, Compare) ->
1643
+ case {Sequences, Direction} of
1644
+ {[], _} ->
1645
+ [];
1646
+
1647
+ {[Sequence], ascending} ->
1648
+ Sequence;
1649
+
1650
+ {[Sequence@1], descending} ->
1651
+ lists:reverse(Sequence@1);
1652
+
1653
+ {_, ascending} ->
1654
+ Sequences@1 = merge_ascending_pairs(Sequences, Compare, []),
1655
+ merge_all(Sequences@1, descending, Compare);
1656
+
1657
+ {_, descending} ->
1658
+ Sequences@2 = merge_descending_pairs(Sequences, Compare, []),
1659
+ merge_all(Sequences@2, ascending, Compare)
1660
+ end.
1661
+
1662
+ -file("src/gleam/list.gleam", 1201).
1663
+ ?DOC(
1664
+ " Sorts from smallest to largest based upon the ordering specified by a given\n"
1665
+ " function.\n"
1666
+ "\n"
1667
+ " ## Examples\n"
1668
+ "\n"
1669
+ " ```gleam\n"
1670
+ " import gleam/int\n"
1671
+ "\n"
1672
+ " sort([4, 3, 6, 5, 4, 1, 2], by: int.compare)\n"
1673
+ " // -> [1, 2, 3, 4, 4, 5, 6]\n"
1674
+ " ```\n"
1675
+ ).
1676
+ -spec sort(list(AJV), fun((AJV, AJV) -> gleam@order:order())) -> list(AJV).
1677
+ sort(List, Compare) ->
1678
+ case List of
1679
+ [] ->
1680
+ [];
1681
+
1682
+ [X] ->
1683
+ [X];
1684
+
1685
+ [X@1, Y | Rest] ->
1686
+ Direction = case Compare(X@1, Y) of
1687
+ lt ->
1688
+ ascending;
1689
+
1690
+ eq ->
1691
+ ascending;
1692
+
1693
+ gt ->
1694
+ descending
1695
+ end,
1696
+ Sequences = sequences(Rest, Compare, [X@1], Direction, Y, []),
1697
+ merge_all(Sequences, ascending, Compare)
1698
+ end.
1699
+
1700
+ -file("src/gleam/list.gleam", 1460).
1701
+ -spec range_loop(integer(), integer(), list(integer())) -> list(integer()).
1702
+ range_loop(Start, Stop, Acc) ->
1703
+ case gleam@int:compare(Start, Stop) of
1704
+ eq ->
1705
+ [Stop | Acc];
1706
+
1707
+ gt ->
1708
+ range_loop(Start, Stop + 1, [Stop | Acc]);
1709
+
1710
+ lt ->
1711
+ range_loop(Start, Stop - 1, [Stop | Acc])
1712
+ end.
1713
+
1714
+ -file("src/gleam/list.gleam", 1456).
1715
+ -spec range(integer(), integer()) -> list(integer()).
1716
+ range(Start, Stop) ->
1717
+ range_loop(Start, Stop, []).
1718
+
1719
+ -file("src/gleam/list.gleam", 1486).
1720
+ -spec repeat_loop(ALK, integer(), list(ALK)) -> list(ALK).
1721
+ repeat_loop(Item, Times, Acc) ->
1722
+ case Times =< 0 of
1723
+ true ->
1724
+ Acc;
1725
+
1726
+ false ->
1727
+ repeat_loop(Item, Times - 1, [Item | Acc])
1728
+ end.
1729
+
1730
+ -file("src/gleam/list.gleam", 1482).
1731
+ ?DOC(
1732
+ " Builds a list of a given value a given number of times.\n"
1733
+ "\n"
1734
+ " ## Examples\n"
1735
+ "\n"
1736
+ " ```gleam\n"
1737
+ " repeat(\"a\", times: 0)\n"
1738
+ " // -> []\n"
1739
+ " ```\n"
1740
+ "\n"
1741
+ " ```gleam\n"
1742
+ " repeat(\"a\", times: 5)\n"
1743
+ " // -> [\"a\", \"a\", \"a\", \"a\", \"a\"]\n"
1744
+ " ```\n"
1745
+ ).
1746
+ -spec repeat(ALI, integer()) -> list(ALI).
1747
+ repeat(A, Times) ->
1748
+ repeat_loop(A, Times, []).
1749
+
1750
+ -file("src/gleam/list.gleam", 1519).
1751
+ -spec split_loop(list(ALR), integer(), list(ALR)) -> {list(ALR), list(ALR)}.
1752
+ split_loop(List, N, Taken) ->
1753
+ case N =< 0 of
1754
+ true ->
1755
+ {lists:reverse(Taken), List};
1756
+
1757
+ false ->
1758
+ case List of
1759
+ [] ->
1760
+ {lists:reverse(Taken), []};
1761
+
1762
+ [First | Rest] ->
1763
+ split_loop(Rest, N - 1, [First | Taken])
1764
+ end
1765
+ end.
1766
+
1767
+ -file("src/gleam/list.gleam", 1515).
1768
+ ?DOC(
1769
+ " Splits a list in two before the given index.\n"
1770
+ "\n"
1771
+ " If the list is not long enough to have the given index the before list will\n"
1772
+ " be the input list, and the after list will be empty.\n"
1773
+ "\n"
1774
+ " ## Examples\n"
1775
+ "\n"
1776
+ " ```gleam\n"
1777
+ " split([6, 7, 8, 9], 0)\n"
1778
+ " // -> #([], [6, 7, 8, 9])\n"
1779
+ " ```\n"
1780
+ "\n"
1781
+ " ```gleam\n"
1782
+ " split([6, 7, 8, 9], 2)\n"
1783
+ " // -> #([6, 7], [8, 9])\n"
1784
+ " ```\n"
1785
+ "\n"
1786
+ " ```gleam\n"
1787
+ " split([6, 7, 8, 9], 4)\n"
1788
+ " // -> #([6, 7, 8, 9], [])\n"
1789
+ " ```\n"
1790
+ ).
1791
+ -spec split(list(ALN), integer()) -> {list(ALN), list(ALN)}.
1792
+ split(List, Index) ->
1793
+ split_loop(List, Index, []).
1794
+
1795
+ -file("src/gleam/list.gleam", 1555).
1796
+ -spec split_while_loop(list(AMA), fun((AMA) -> boolean()), list(AMA)) -> {list(AMA),
1797
+ list(AMA)}.
1798
+ split_while_loop(List, F, Acc) ->
1799
+ case List of
1800
+ [] ->
1801
+ {lists:reverse(Acc), []};
1802
+
1803
+ [First | Rest] ->
1804
+ case F(First) of
1805
+ true ->
1806
+ split_while_loop(Rest, F, [First | Acc]);
1807
+
1808
+ false ->
1809
+ {lists:reverse(Acc), List}
1810
+ end
1811
+ end.
1812
+
1813
+ -file("src/gleam/list.gleam", 1548).
1814
+ ?DOC(
1815
+ " Splits a list in two before the first element that a given function returns\n"
1816
+ " `False` for.\n"
1817
+ "\n"
1818
+ " If the function returns `True` for all elements the first list will be the\n"
1819
+ " input list, and the second list will be empty.\n"
1820
+ "\n"
1821
+ " ## Examples\n"
1822
+ "\n"
1823
+ " ```gleam\n"
1824
+ " split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 })\n"
1825
+ " // -> #([1, 2, 3], [4, 5])\n"
1826
+ " ```\n"
1827
+ "\n"
1828
+ " ```gleam\n"
1829
+ " split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 })\n"
1830
+ " // -> #([1, 2, 3, 4, 5], [])\n"
1831
+ " ```\n"
1832
+ ).
1833
+ -spec split_while(list(ALW), fun((ALW) -> boolean())) -> {list(ALW), list(ALW)}.
1834
+ split_while(List, Predicate) ->
1835
+ split_while_loop(List, Predicate, []).
1836
+
1837
+ -file("src/gleam/list.gleam", 1595).
1838
+ ?DOC(
1839
+ " Given a list of 2-element tuples, finds the first tuple that has a given\n"
1840
+ " key as the first element and returns the second element.\n"
1841
+ "\n"
1842
+ " If no tuple is found with the given key then `Error(Nil)` is returned.\n"
1843
+ "\n"
1844
+ " This function may be useful for interacting with Erlang code where lists of\n"
1845
+ " tuples are common.\n"
1846
+ "\n"
1847
+ " ## Examples\n"
1848
+ "\n"
1849
+ " ```gleam\n"
1850
+ " key_find([#(\"a\", 0), #(\"b\", 1)], \"a\")\n"
1851
+ " // -> Ok(0)\n"
1852
+ " ```\n"
1853
+ "\n"
1854
+ " ```gleam\n"
1855
+ " key_find([#(\"a\", 0), #(\"b\", 1)], \"b\")\n"
1856
+ " // -> Ok(1)\n"
1857
+ " ```\n"
1858
+ "\n"
1859
+ " ```gleam\n"
1860
+ " key_find([#(\"a\", 0), #(\"b\", 1)], \"c\")\n"
1861
+ " // -> Error(Nil)\n"
1862
+ " ```\n"
1863
+ ).
1864
+ -spec key_find(list({AMF, AMG}), AMF) -> {ok, AMG} | {error, nil}.
1865
+ key_find(Keyword_list, Desired_key) ->
1866
+ find_map(
1867
+ Keyword_list,
1868
+ fun(Keyword) ->
1869
+ {Key, Value} = Keyword,
1870
+ case Key =:= Desired_key of
1871
+ true ->
1872
+ {ok, Value};
1873
+
1874
+ false ->
1875
+ {error, nil}
1876
+ end
1877
+ end
1878
+ ).
1879
+
1880
+ -file("src/gleam/list.gleam", 1626).
1881
+ ?DOC(
1882
+ " Given a list of 2-element tuples, finds all tuples that have a given\n"
1883
+ " key as the first element and returns the second element.\n"
1884
+ "\n"
1885
+ " This function may be useful for interacting with Erlang code where lists of\n"
1886
+ " tuples are common.\n"
1887
+ "\n"
1888
+ " ## Examples\n"
1889
+ "\n"
1890
+ " ```gleam\n"
1891
+ " key_filter([#(\"a\", 0), #(\"b\", 1), #(\"a\", 2)], \"a\")\n"
1892
+ " // -> [0, 2]\n"
1893
+ " ```\n"
1894
+ "\n"
1895
+ " ```gleam\n"
1896
+ " key_filter([#(\"a\", 0), #(\"b\", 1)], \"c\")\n"
1897
+ " // -> []\n"
1898
+ " ```\n"
1899
+ ).
1900
+ -spec key_filter(list({AMK, AML}), AMK) -> list(AML).
1901
+ key_filter(Keyword_list, Desired_key) ->
1902
+ filter_map(
1903
+ Keyword_list,
1904
+ fun(Keyword) ->
1905
+ {Key, Value} = Keyword,
1906
+ case Key =:= Desired_key of
1907
+ true ->
1908
+ {ok, Value};
1909
+
1910
+ false ->
1911
+ {error, nil}
1912
+ end
1913
+ end
1914
+ ).
1915
+
1916
+ -file("src/gleam/list.gleam", 1666).
1917
+ -spec key_pop_loop(list({AMU, AMV}), AMU, list({AMU, AMV})) -> {ok,
1918
+ {AMV, list({AMU, AMV})}} |
1919
+ {error, nil}.
1920
+ key_pop_loop(List, Key, Checked) ->
1921
+ case List of
1922
+ [] ->
1923
+ {error, nil};
1924
+
1925
+ [{K, V} | Rest] when K =:= Key ->
1926
+ {ok, {V, lists:reverse(Checked, Rest)}};
1927
+
1928
+ [First | Rest@1] ->
1929
+ key_pop_loop(Rest@1, Key, [First | Checked])
1930
+ end.
1931
+
1932
+ -file("src/gleam/list.gleam", 1662).
1933
+ ?DOC(
1934
+ " Given a list of 2-element tuples, finds the first tuple that has a given\n"
1935
+ " key as the first element. This function will return the second element\n"
1936
+ " of the found tuple and list with tuple removed.\n"
1937
+ "\n"
1938
+ " If no tuple is found with the given key then `Error(Nil)` is returned.\n"
1939
+ "\n"
1940
+ " ## Examples\n"
1941
+ "\n"
1942
+ " ```gleam\n"
1943
+ " key_pop([#(\"a\", 0), #(\"b\", 1)], \"a\")\n"
1944
+ " // -> Ok(#(0, [#(\"b\", 1)]))\n"
1945
+ " ```\n"
1946
+ "\n"
1947
+ " ```gleam\n"
1948
+ " key_pop([#(\"a\", 0), #(\"b\", 1)], \"b\")\n"
1949
+ " // -> Ok(#(1, [#(\"a\", 0)]))\n"
1950
+ " ```\n"
1951
+ "\n"
1952
+ " ```gleam\n"
1953
+ " key_pop([#(\"a\", 0), #(\"b\", 1)], \"c\")\n"
1954
+ " // -> Error(Nil)\n"
1955
+ " ```\n"
1956
+ ).
1957
+ -spec key_pop(list({AMO, AMP}), AMO) -> {ok, {AMP, list({AMO, AMP})}} |
1958
+ {error, nil}.
1959
+ key_pop(List, Key) ->
1960
+ key_pop_loop(List, Key, []).
1961
+
1962
+ -file("src/gleam/list.gleam", 1700).
1963
+ -spec key_set_loop(list({ANF, ANG}), ANF, ANG, list({ANF, ANG})) -> list({ANF,
1964
+ ANG}).
1965
+ key_set_loop(List, Key, Value, Inspected) ->
1966
+ case List of
1967
+ [{K, _} | Rest] when K =:= Key ->
1968
+ lists:reverse(Inspected, [{K, Value} | Rest]);
1969
+
1970
+ [First | Rest@1] ->
1971
+ key_set_loop(Rest@1, Key, Value, [First | Inspected]);
1972
+
1973
+ [] ->
1974
+ lists:reverse([{Key, Value} | Inspected])
1975
+ end.
1976
+
1977
+ -file("src/gleam/list.gleam", 1696).
1978
+ ?DOC(
1979
+ " Given a list of 2-element tuples, inserts a key and value into the list.\n"
1980
+ "\n"
1981
+ " If there was already a tuple with the key then it is replaced, otherwise it\n"
1982
+ " is added to the end of the list.\n"
1983
+ "\n"
1984
+ " ## Examples\n"
1985
+ "\n"
1986
+ " ```gleam\n"
1987
+ " key_set([#(5, 0), #(4, 1)], 4, 100)\n"
1988
+ " // -> [#(5, 0), #(4, 100)]\n"
1989
+ " ```\n"
1990
+ "\n"
1991
+ " ```gleam\n"
1992
+ " key_set([#(5, 0), #(4, 1)], 1, 100)\n"
1993
+ " // -> [#(5, 0), #(4, 1), #(1, 100)]\n"
1994
+ " ```\n"
1995
+ ).
1996
+ -spec key_set(list({ANB, ANC}), ANB, ANC) -> list({ANB, ANC}).
1997
+ key_set(List, Key, Value) ->
1998
+ key_set_loop(List, Key, Value, []).
1999
+
2000
+ -file("src/gleam/list.gleam", 1728).
2001
+ ?DOC(
2002
+ " Calls a function for each element in a list, discarding the return value.\n"
2003
+ "\n"
2004
+ " Useful for calling a side effect for every item of a list.\n"
2005
+ "\n"
2006
+ " ```gleam\n"
2007
+ " import gleam/io\n"
2008
+ "\n"
2009
+ " each([\"1\", \"2\", \"3\"], io.println)\n"
2010
+ " // -> Nil\n"
2011
+ " // 1\n"
2012
+ " // 2\n"
2013
+ " // 3\n"
2014
+ " ```\n"
2015
+ ).
2016
+ -spec each(list(ANK), fun((ANK) -> any())) -> nil.
2017
+ each(List, F) ->
2018
+ case List of
2019
+ [] ->
2020
+ nil;
2021
+
2022
+ [First | Rest] ->
2023
+ F(First),
2024
+ each(Rest, F)
2025
+ end.
2026
+
2027
+ -file("src/gleam/list.gleam", 1754).
2028
+ ?DOC(
2029
+ " Calls a `Result` returning function for each element in a list, discarding\n"
2030
+ " the return value. If the function returns `Error` then the iteration is\n"
2031
+ " stopped and the error is returned.\n"
2032
+ "\n"
2033
+ " Useful for calling a side effect for every item of a list.\n"
2034
+ "\n"
2035
+ " ## Examples\n"
2036
+ "\n"
2037
+ " ```gleam\n"
2038
+ " try_each(\n"
2039
+ " over: [1, 2, 3],\n"
2040
+ " with: function_that_might_fail,\n"
2041
+ " )\n"
2042
+ " // -> Ok(Nil)\n"
2043
+ " ```\n"
2044
+ ).
2045
+ -spec try_each(list(ANN), fun((ANN) -> {ok, any()} | {error, ANQ})) -> {ok, nil} |
2046
+ {error, ANQ}.
2047
+ try_each(List, Fun) ->
2048
+ case List of
2049
+ [] ->
2050
+ {ok, nil};
2051
+
2052
+ [First | Rest] ->
2053
+ case Fun(First) of
2054
+ {ok, _} ->
2055
+ try_each(Rest, Fun);
2056
+
2057
+ {error, E} ->
2058
+ {error, E}
2059
+ end
2060
+ end.
2061
+
2062
+ -file("src/gleam/list.gleam", 1787).
2063
+ -spec partition_loop(list(BGQ), fun((BGQ) -> boolean()), list(BGQ), list(BGQ)) -> {list(BGQ),
2064
+ list(BGQ)}.
2065
+ partition_loop(List, Categorise, Trues, Falses) ->
2066
+ case List of
2067
+ [] ->
2068
+ {lists:reverse(Trues), lists:reverse(Falses)};
2069
+
2070
+ [First | Rest] ->
2071
+ case Categorise(First) of
2072
+ true ->
2073
+ partition_loop(Rest, Categorise, [First | Trues], Falses);
2074
+
2075
+ false ->
2076
+ partition_loop(Rest, Categorise, Trues, [First | Falses])
2077
+ end
2078
+ end.
2079
+
2080
+ -file("src/gleam/list.gleam", 1780).
2081
+ ?DOC(
2082
+ " Partitions a list into a tuple/pair of lists\n"
2083
+ " by a given categorisation function.\n"
2084
+ "\n"
2085
+ " ## Examples\n"
2086
+ "\n"
2087
+ " ```gleam\n"
2088
+ " import gleam/int\n"
2089
+ "\n"
2090
+ " [1, 2, 3, 4, 5] |> partition(int.is_odd)\n"
2091
+ " // -> #([1, 3, 5], [2, 4])\n"
2092
+ " ```\n"
2093
+ ).
2094
+ -spec partition(list(ANV), fun((ANV) -> boolean())) -> {list(ANV), list(ANV)}.
2095
+ partition(List, Categorise) ->
2096
+ partition_loop(List, Categorise, [], []).
2097
+
2098
+ -file("src/gleam/list.gleam", 1867).
2099
+ -spec window_loop(list(list(APC)), list(APC), integer()) -> list(list(APC)).
2100
+ window_loop(Acc, List, N) ->
2101
+ Window = take(List, N),
2102
+ case erlang:length(Window) =:= N of
2103
+ true ->
2104
+ window_loop([Window | Acc], drop(List, 1), N);
2105
+
2106
+ false ->
2107
+ lists:reverse(Acc)
2108
+ end.
2109
+
2110
+ -file("src/gleam/list.gleam", 1860).
2111
+ ?DOC(
2112
+ " Returns a list of sliding windows.\n"
2113
+ "\n"
2114
+ " ## Examples\n"
2115
+ "\n"
2116
+ " ```gleam\n"
2117
+ " window([1,2,3,4,5], 3)\n"
2118
+ " // -> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]\n"
2119
+ " ```\n"
2120
+ "\n"
2121
+ " ```gleam\n"
2122
+ " window([1, 2], 4)\n"
2123
+ " // -> []\n"
2124
+ " ```\n"
2125
+ ).
2126
+ -spec window(list(AOY), integer()) -> list(list(AOY)).
2127
+ window(List, N) ->
2128
+ case N =< 0 of
2129
+ true ->
2130
+ [];
2131
+
2132
+ false ->
2133
+ window_loop([], List, N)
2134
+ end.
2135
+
2136
+ -file("src/gleam/list.gleam", 1890).
2137
+ ?DOC(
2138
+ " Returns a list of tuples containing two contiguous elements.\n"
2139
+ "\n"
2140
+ " ## Examples\n"
2141
+ "\n"
2142
+ " ```gleam\n"
2143
+ " window_by_2([1,2,3,4])\n"
2144
+ " // -> [#(1, 2), #(2, 3), #(3, 4)]\n"
2145
+ " ```\n"
2146
+ "\n"
2147
+ " ```gleam\n"
2148
+ " window_by_2([1])\n"
2149
+ " // -> []\n"
2150
+ " ```\n"
2151
+ ).
2152
+ -spec window_by_2(list(API)) -> list({API, API}).
2153
+ window_by_2(List) ->
2154
+ zip(List, drop(List, 1)).
2155
+
2156
+ -file("src/gleam/list.gleam", 1903).
2157
+ ?DOC(
2158
+ " Drops the first elements in a given list for which the predicate function returns `True`.\n"
2159
+ "\n"
2160
+ " ## Examples\n"
2161
+ "\n"
2162
+ " ```gleam\n"
2163
+ " drop_while([1, 2, 3, 4], fn (x) { x < 3 })\n"
2164
+ " // -> [3, 4]\n"
2165
+ " ```\n"
2166
+ ).
2167
+ -spec drop_while(list(APL), fun((APL) -> boolean())) -> list(APL).
2168
+ drop_while(List, Predicate) ->
2169
+ case List of
2170
+ [] ->
2171
+ [];
2172
+
2173
+ [First | Rest] ->
2174
+ case Predicate(First) of
2175
+ true ->
2176
+ drop_while(Rest, Predicate);
2177
+
2178
+ false ->
2179
+ [First | Rest]
2180
+ end
2181
+ end.
2182
+
2183
+ -file("src/gleam/list.gleam", 1933).
2184
+ -spec take_while_loop(list(APR), fun((APR) -> boolean()), list(APR)) -> list(APR).
2185
+ take_while_loop(List, Predicate, Acc) ->
2186
+ case List of
2187
+ [] ->
2188
+ lists:reverse(Acc);
2189
+
2190
+ [First | Rest] ->
2191
+ case Predicate(First) of
2192
+ true ->
2193
+ take_while_loop(Rest, Predicate, [First | Acc]);
2194
+
2195
+ false ->
2196
+ lists:reverse(Acc)
2197
+ end
2198
+ end.
2199
+
2200
+ -file("src/gleam/list.gleam", 1926).
2201
+ ?DOC(
2202
+ " Takes the first elements in a given list for which the predicate function returns `True`.\n"
2203
+ "\n"
2204
+ " ## Examples\n"
2205
+ "\n"
2206
+ " ```gleam\n"
2207
+ " take_while([1, 2, 3, 2, 4], fn (x) { x < 3 })\n"
2208
+ " // -> [1, 2]\n"
2209
+ " ```\n"
2210
+ ).
2211
+ -spec take_while(list(APO), fun((APO) -> boolean())) -> list(APO).
2212
+ take_while(List, Predicate) ->
2213
+ take_while_loop(List, Predicate, []).
2214
+
2215
+ -file("src/gleam/list.gleam", 1965).
2216
+ -spec chunk_loop(list(AQA), fun((AQA) -> AQC), AQC, list(AQA), list(list(AQA))) -> list(list(AQA)).
2217
+ chunk_loop(List, F, Previous_key, Current_chunk, Acc) ->
2218
+ case List of
2219
+ [First | Rest] ->
2220
+ Key = F(First),
2221
+ case Key =:= Previous_key of
2222
+ true ->
2223
+ chunk_loop(Rest, F, Key, [First | Current_chunk], Acc);
2224
+
2225
+ false ->
2226
+ New_acc = [lists:reverse(Current_chunk) | Acc],
2227
+ chunk_loop(Rest, F, Key, [First], New_acc)
2228
+ end;
2229
+
2230
+ [] ->
2231
+ lists:reverse([lists:reverse(Current_chunk) | Acc])
2232
+ end.
2233
+
2234
+ -file("src/gleam/list.gleam", 1958).
2235
+ ?DOC(
2236
+ " Returns a list of chunks in which\n"
2237
+ " the return value of calling `f` on each element is the same.\n"
2238
+ "\n"
2239
+ " ## Examples\n"
2240
+ "\n"
2241
+ " ```gleam\n"
2242
+ " [1, 2, 2, 3, 4, 4, 6, 7, 7] |> chunk(by: fn(n) { n % 2 })\n"
2243
+ " // -> [[1], [2, 2], [3], [4, 4, 6], [7, 7]]\n"
2244
+ " ```\n"
2245
+ ).
2246
+ -spec chunk(list(APV), fun((APV) -> any())) -> list(list(APV)).
2247
+ chunk(List, F) ->
2248
+ case List of
2249
+ [] ->
2250
+ [];
2251
+
2252
+ [First | Rest] ->
2253
+ chunk_loop(Rest, F, F(First), [First], [])
2254
+ end.
2255
+
2256
+ -file("src/gleam/list.gleam", 2010).
2257
+ -spec sized_chunk_loop(
2258
+ list(AQM),
2259
+ integer(),
2260
+ integer(),
2261
+ list(AQM),
2262
+ list(list(AQM))
2263
+ ) -> list(list(AQM)).
2264
+ sized_chunk_loop(List, Count, Left, Current_chunk, Acc) ->
2265
+ case List of
2266
+ [] ->
2267
+ case Current_chunk of
2268
+ [] ->
2269
+ lists:reverse(Acc);
2270
+
2271
+ Remaining ->
2272
+ lists:reverse([lists:reverse(Remaining) | Acc])
2273
+ end;
2274
+
2275
+ [First | Rest] ->
2276
+ Chunk = [First | Current_chunk],
2277
+ case Left > 1 of
2278
+ true ->
2279
+ sized_chunk_loop(Rest, Count, Left - 1, Chunk, Acc);
2280
+
2281
+ false ->
2282
+ sized_chunk_loop(
2283
+ Rest,
2284
+ Count,
2285
+ Count,
2286
+ [],
2287
+ [lists:reverse(Chunk) | Acc]
2288
+ )
2289
+ end
2290
+ end.
2291
+
2292
+ -file("src/gleam/list.gleam", 2006).
2293
+ ?DOC(
2294
+ " Returns a list of chunks containing `count` elements each.\n"
2295
+ "\n"
2296
+ " If the last chunk does not have `count` elements, it is instead\n"
2297
+ " a partial chunk, with less than `count` elements.\n"
2298
+ "\n"
2299
+ " For any `count` less than 1 this function behaves as if it was set to 1.\n"
2300
+ "\n"
2301
+ " ## Examples\n"
2302
+ "\n"
2303
+ " ```gleam\n"
2304
+ " [1, 2, 3, 4, 5, 6] |> sized_chunk(into: 2)\n"
2305
+ " // -> [[1, 2], [3, 4], [5, 6]]\n"
2306
+ " ```\n"
2307
+ "\n"
2308
+ " ```gleam\n"
2309
+ " [1, 2, 3, 4, 5, 6, 7, 8] |> sized_chunk(into: 3)\n"
2310
+ " // -> [[1, 2, 3], [4, 5, 6], [7, 8]]\n"
2311
+ " ```\n"
2312
+ ).
2313
+ -spec sized_chunk(list(AQI), integer()) -> list(list(AQI)).
2314
+ sized_chunk(List, Count) ->
2315
+ sized_chunk_loop(List, Count, Count, [], []).
2316
+
2317
+ -file("src/gleam/list.gleam", 2054).
2318
+ ?DOC(
2319
+ " This function acts similar to fold, but does not take an initial state.\n"
2320
+ " Instead, it starts from the first element in the list\n"
2321
+ " and combines it with each subsequent element in turn using the given\n"
2322
+ " function. The function is called as `fun(accumulator, current_element)`.\n"
2323
+ "\n"
2324
+ " Returns `Ok` to indicate a successful run, and `Error` if called on an\n"
2325
+ " empty list.\n"
2326
+ "\n"
2327
+ " ## Examples\n"
2328
+ "\n"
2329
+ " ```gleam\n"
2330
+ " [] |> reduce(fn(acc, x) { acc + x })\n"
2331
+ " // -> Error(Nil)\n"
2332
+ " ```\n"
2333
+ "\n"
2334
+ " ```gleam\n"
2335
+ " [1, 2, 3, 4, 5] |> reduce(fn(acc, x) { acc + x })\n"
2336
+ " // -> Ok(15)\n"
2337
+ " ```\n"
2338
+ ).
2339
+ -spec reduce(list(AQT), fun((AQT, AQT) -> AQT)) -> {ok, AQT} | {error, nil}.
2340
+ reduce(List, Fun) ->
2341
+ case List of
2342
+ [] ->
2343
+ {error, nil};
2344
+
2345
+ [First | Rest] ->
2346
+ {ok, fold(Rest, First, Fun)}
2347
+ end.
2348
+
2349
+ -file("src/gleam/list.gleam", 2078).
2350
+ -spec scan_loop(list(ARB), ARD, list(ARD), fun((ARD, ARB) -> ARD)) -> list(ARD).
2351
+ scan_loop(List, Accumulator, Accumulated, Fun) ->
2352
+ case List of
2353
+ [] ->
2354
+ lists:reverse(Accumulated);
2355
+
2356
+ [First | Rest] ->
2357
+ Next = Fun(Accumulator, First),
2358
+ scan_loop(Rest, Next, [Next | Accumulated], Fun)
2359
+ end.
2360
+
2361
+ -file("src/gleam/list.gleam", 2070).
2362
+ ?DOC(
2363
+ " Similar to `fold`, but yields the state of the accumulator at each stage.\n"
2364
+ "\n"
2365
+ " ## Examples\n"
2366
+ "\n"
2367
+ " ```gleam\n"
2368
+ " scan(over: [1, 2, 3], from: 100, with: fn(acc, i) { acc + i })\n"
2369
+ " // -> [101, 103, 106]\n"
2370
+ " ```\n"
2371
+ ).
2372
+ -spec scan(list(AQX), AQZ, fun((AQZ, AQX) -> AQZ)) -> list(AQZ).
2373
+ scan(List, Initial, Fun) ->
2374
+ scan_loop(List, Initial, [], Fun).
2375
+
2376
+ -file("src/gleam/list.gleam", 2111).
2377
+ ?DOC(
2378
+ " Returns the last element in the given list.\n"
2379
+ "\n"
2380
+ " Returns `Error(Nil)` if the list is empty.\n"
2381
+ "\n"
2382
+ " This function runs in linear time.\n"
2383
+ "\n"
2384
+ " ## Examples\n"
2385
+ "\n"
2386
+ " ```gleam\n"
2387
+ " last([])\n"
2388
+ " // -> Error(Nil)\n"
2389
+ " ```\n"
2390
+ "\n"
2391
+ " ```gleam\n"
2392
+ " last([1, 2, 3, 4, 5])\n"
2393
+ " // -> Ok(5)\n"
2394
+ " ```\n"
2395
+ ).
2396
+ -spec last(list(ARG)) -> {ok, ARG} | {error, nil}.
2397
+ last(List) ->
2398
+ case List of
2399
+ [] ->
2400
+ {error, nil};
2401
+
2402
+ [Last] ->
2403
+ {ok, Last};
2404
+
2405
+ [_ | Rest] ->
2406
+ last(Rest)
2407
+ end.
2408
+
2409
+ -file("src/gleam/list.gleam", 2133).
2410
+ ?DOC(
2411
+ " Return unique combinations of elements in the list.\n"
2412
+ "\n"
2413
+ " ## Examples\n"
2414
+ "\n"
2415
+ " ```gleam\n"
2416
+ " combinations([1, 2, 3], 2)\n"
2417
+ " // -> [[1, 2], [1, 3], [2, 3]]\n"
2418
+ " ```\n"
2419
+ "\n"
2420
+ " ```gleam\n"
2421
+ " combinations([1, 2, 3, 4], 3)\n"
2422
+ " // -> [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]\n"
2423
+ " ```\n"
2424
+ ).
2425
+ -spec combinations(list(ARK), integer()) -> list(list(ARK)).
2426
+ combinations(Items, N) ->
2427
+ case {N, Items} of
2428
+ {0, _} ->
2429
+ [[]];
2430
+
2431
+ {_, []} ->
2432
+ [];
2433
+
2434
+ {_, [First | Rest]} ->
2435
+ _pipe = Rest,
2436
+ _pipe@1 = combinations(_pipe, N - 1),
2437
+ _pipe@2 = map(
2438
+ _pipe@1,
2439
+ fun(Combination) -> [First | Combination] end
2440
+ ),
2441
+ _pipe@3 = lists:reverse(_pipe@2),
2442
+ fold(_pipe@3, combinations(Rest, N), fun(Acc, C) -> [C | Acc] end)
2443
+ end.
2444
+
2445
+ -file("src/gleam/list.gleam", 2159).
2446
+ -spec combination_pairs_loop(list(ARR), list({ARR, ARR})) -> list({ARR, ARR}).
2447
+ combination_pairs_loop(Items, Acc) ->
2448
+ case Items of
2449
+ [] ->
2450
+ lists:reverse(Acc);
2451
+
2452
+ [First | Rest] ->
2453
+ First_combinations = map(Rest, fun(Other) -> {First, Other} end),
2454
+ Acc@1 = lists:reverse(First_combinations, Acc),
2455
+ combination_pairs_loop(Rest, Acc@1)
2456
+ end.
2457
+
2458
+ -file("src/gleam/list.gleam", 2155).
2459
+ ?DOC(
2460
+ " Return unique pair combinations of elements in the list.\n"
2461
+ "\n"
2462
+ " ## Examples\n"
2463
+ "\n"
2464
+ " ```gleam\n"
2465
+ " combination_pairs([1, 2, 3])\n"
2466
+ " // -> [#(1, 2), #(1, 3), #(2, 3)]\n"
2467
+ " ```\n"
2468
+ ).
2469
+ -spec combination_pairs(list(ARO)) -> list({ARO, ARO}).
2470
+ combination_pairs(Items) ->
2471
+ combination_pairs_loop(Items, []).
2472
+
2473
+ -file("src/gleam/list.gleam", 2215).
2474
+ -spec take_firsts(list(list(ASL)), list(ASL), list(list(ASL))) -> {list(ASL),
2475
+ list(list(ASL))}.
2476
+ take_firsts(Rows, Column, Remaining_rows) ->
2477
+ case Rows of
2478
+ [] ->
2479
+ {lists:reverse(Column), lists:reverse(Remaining_rows)};
2480
+
2481
+ [[] | Rest] ->
2482
+ take_firsts(Rest, Column, Remaining_rows);
2483
+
2484
+ [[First | Remaining_row] | Rest_rows] ->
2485
+ Remaining_rows@1 = [Remaining_row | Remaining_rows],
2486
+ take_firsts(Rest_rows, [First | Column], Remaining_rows@1)
2487
+ end.
2488
+
2489
+ -file("src/gleam/list.gleam", 2202).
2490
+ -spec transpose_loop(list(list(ASE)), list(list(ASE))) -> list(list(ASE)).
2491
+ transpose_loop(Rows, Columns) ->
2492
+ case Rows of
2493
+ [] ->
2494
+ lists:reverse(Columns);
2495
+
2496
+ _ ->
2497
+ {Column, Rest} = take_firsts(Rows, [], []),
2498
+ case Column of
2499
+ [_ | _] ->
2500
+ transpose_loop(Rest, [Column | Columns]);
2501
+
2502
+ [] ->
2503
+ transpose_loop(Rest, Columns)
2504
+ end
2505
+ end.
2506
+
2507
+ -file("src/gleam/list.gleam", 2198).
2508
+ ?DOC(
2509
+ " Transpose rows and columns of the list of lists.\n"
2510
+ "\n"
2511
+ " Notice: This function is not tail recursive,\n"
2512
+ " and thus may exceed stack size if called,\n"
2513
+ " with large lists (on the JavaScript target).\n"
2514
+ "\n"
2515
+ " ## Examples\n"
2516
+ "\n"
2517
+ " ```gleam\n"
2518
+ " transpose([[1, 2, 3], [101, 102, 103]])\n"
2519
+ " // -> [[1, 101], [2, 102], [3, 103]]\n"
2520
+ " ```\n"
2521
+ ).
2522
+ -spec transpose(list(list(ARZ))) -> list(list(ARZ)).
2523
+ transpose(List_of_lists) ->
2524
+ transpose_loop(List_of_lists, []).
2525
+
2526
+ -file("src/gleam/list.gleam", 2179).
2527
+ ?DOC(
2528
+ " Make a list alternating the elements from the given lists\n"
2529
+ "\n"
2530
+ " ## Examples\n"
2531
+ "\n"
2532
+ " ```gleam\n"
2533
+ " interleave([[1, 2], [101, 102], [201, 202]])\n"
2534
+ " // -> [1, 101, 201, 2, 102, 202]\n"
2535
+ " ```\n"
2536
+ ).
2537
+ -spec interleave(list(list(ARV))) -> list(ARV).
2538
+ interleave(List) ->
2539
+ _pipe = List,
2540
+ _pipe@1 = transpose(_pipe),
2541
+ lists:append(_pipe@1).
2542
+
2543
+ -file("src/gleam/list.gleam", 2248).
2544
+ -spec shuffle_pair_unwrap_loop(list({float(), ASX}), list(ASX)) -> list(ASX).
2545
+ shuffle_pair_unwrap_loop(List, Acc) ->
2546
+ case List of
2547
+ [] ->
2548
+ Acc;
2549
+
2550
+ [Elem_pair | Enumerable] ->
2551
+ shuffle_pair_unwrap_loop(
2552
+ Enumerable,
2553
+ [erlang:element(2, Elem_pair) | Acc]
2554
+ )
2555
+ end.
2556
+
2557
+ -file("src/gleam/list.gleam", 2256).
2558
+ -spec do_shuffle_by_pair_indexes(list({float(), ATB})) -> list({float(), ATB}).
2559
+ do_shuffle_by_pair_indexes(List_of_pairs) ->
2560
+ sort(
2561
+ List_of_pairs,
2562
+ fun(A_pair, B_pair) ->
2563
+ gleam@float:compare(
2564
+ erlang:element(1, A_pair),
2565
+ erlang:element(1, B_pair)
2566
+ )
2567
+ end
2568
+ ).
2569
+
2570
+ -file("src/gleam/list.gleam", 2241).
2571
+ ?DOC(
2572
+ " Takes a list, randomly sorts all items and returns the shuffled list.\n"
2573
+ "\n"
2574
+ " This function uses `float.random` to decide the order of the elements.\n"
2575
+ "\n"
2576
+ " ## Example\n"
2577
+ "\n"
2578
+ " ```gleam\n"
2579
+ " range(1, 10) |> shuffle()\n"
2580
+ " // -> [1, 6, 9, 10, 3, 8, 4, 2, 7, 5]\n"
2581
+ " ```\n"
2582
+ ).
2583
+ -spec shuffle(list(ASU)) -> list(ASU).
2584
+ shuffle(List) ->
2585
+ _pipe = List,
2586
+ _pipe@1 = fold(_pipe, [], fun(Acc, A) -> [{rand:uniform(), A} | Acc] end),
2587
+ _pipe@2 = do_shuffle_by_pair_indexes(_pipe@1),
2588
+ shuffle_pair_unwrap_loop(_pipe@2, []).
2589
+
2590
+ -file("src/gleam/list.gleam", 2288).
2591
+ -spec max_loop(list(ATL), fun((ATL, ATL) -> gleam@order:order()), ATL) -> ATL.
2592
+ max_loop(List, Compare, Max) ->
2593
+ case List of
2594
+ [] ->
2595
+ Max;
2596
+
2597
+ [First | Rest] ->
2598
+ case Compare(First, Max) of
2599
+ gt ->
2600
+ max_loop(Rest, Compare, First);
2601
+
2602
+ lt ->
2603
+ max_loop(Rest, Compare, Max);
2604
+
2605
+ eq ->
2606
+ max_loop(Rest, Compare, Max)
2607
+ end
2608
+ end.
2609
+
2610
+ -file("src/gleam/list.gleam", 2278).
2611
+ ?DOC(
2612
+ " Takes a list and a comparator, and returns the maximum element in the list\n"
2613
+ "\n"
2614
+ " ## Examples\n"
2615
+ "\n"
2616
+ " ```gleam\n"
2617
+ " range(1, 10) |> list.max(int.compare)\n"
2618
+ " // -> Ok(10)\n"
2619
+ " ```\n"
2620
+ "\n"
2621
+ " ```gleam\n"
2622
+ " [\"a\", \"c\", \"b\"] |> list.max(string.compare)\n"
2623
+ " // -> Ok(\"c\")\n"
2624
+ " ```\n"
2625
+ ).
2626
+ -spec max(list(ATE), fun((ATE, ATE) -> gleam@order:order())) -> {ok, ATE} |
2627
+ {error, nil}.
2628
+ max(List, Compare) ->
2629
+ case List of
2630
+ [] ->
2631
+ {error, nil};
2632
+
2633
+ [First | Rest] ->
2634
+ {ok, max_loop(Rest, Compare, First)}
2635
+ end.
2636
+
2637
+ -file("src/gleam/list.gleam", 2369).
2638
+ -spec build_reservoir_loop(
2639
+ list(AUA),
2640
+ integer(),
2641
+ gleam@dict:dict(integer(), AUA)
2642
+ ) -> {gleam@dict:dict(integer(), AUA), list(AUA)}.
2643
+ build_reservoir_loop(List, Size, Reservoir) ->
2644
+ Reservoir_size = maps:size(Reservoir),
2645
+ case Reservoir_size >= Size of
2646
+ true ->
2647
+ {Reservoir, List};
2648
+
2649
+ false ->
2650
+ case List of
2651
+ [] ->
2652
+ {Reservoir, []};
2653
+
2654
+ [First | Rest] ->
2655
+ Reservoir@1 = gleam@dict:insert(
2656
+ Reservoir,
2657
+ Reservoir_size,
2658
+ First
2659
+ ),
2660
+ build_reservoir_loop(Rest, Size, Reservoir@1)
2661
+ end
2662
+ end.
2663
+
2664
+ -file("src/gleam/list.gleam", 2365).
2665
+ ?DOC(
2666
+ " Builds the initial reservoir used by Algorithm L.\n"
2667
+ " This is a dictionary with keys ranging from `0` up to `n - 1` where each\n"
2668
+ " value is the corresponding element at that position in `list`.\n"
2669
+ "\n"
2670
+ " This also returns the remaining elements of `list` that didn't end up in\n"
2671
+ " the reservoir.\n"
2672
+ ).
2673
+ -spec build_reservoir(list(ATV), integer()) -> {gleam@dict:dict(integer(), ATV),
2674
+ list(ATV)}.
2675
+ build_reservoir(List, N) ->
2676
+ build_reservoir_loop(List, N, maps:new()).
2677
+
2678
+ -file("src/gleam/list.gleam", 2353).
2679
+ -spec log_random() -> float().
2680
+ log_random() ->
2681
+ Random@1 = case gleam@float:logarithm(
2682
+ rand:uniform() + 2.2250738585072014e-308
2683
+ ) of
2684
+ {ok, Random} -> Random;
2685
+ _assert_fail ->
2686
+ erlang:error(#{gleam_error => let_assert,
2687
+ message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
2688
+ file => <<?FILEPATH/utf8>>,
2689
+ module => <<"gleam/list"/utf8>>,
2690
+ function => <<"log_random"/utf8>>,
2691
+ line => 2354,
2692
+ value => _assert_fail,
2693
+ start => 55356,
2694
+ 'end' => 55427,
2695
+ pattern_start => 55367,
2696
+ pattern_end => 55377})
2697
+ end,
2698
+ Random@1.
2699
+
2700
+ -file("src/gleam/list.gleam", 2330).
2701
+ -spec sample_loop(
2702
+ list(ATP),
2703
+ gleam@dict:dict(integer(), ATP),
2704
+ integer(),
2705
+ float()
2706
+ ) -> gleam@dict:dict(integer(), ATP).
2707
+ sample_loop(List, Reservoir, N, W) ->
2708
+ Skip = begin
2709
+ Log@1 = case gleam@float:logarithm(1.0 - W) of
2710
+ {ok, Log} -> Log;
2711
+ _assert_fail ->
2712
+ erlang:error(#{gleam_error => let_assert,
2713
+ message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
2714
+ file => <<?FILEPATH/utf8>>,
2715
+ module => <<"gleam/list"/utf8>>,
2716
+ function => <<"sample_loop"/utf8>>,
2717
+ line => 2337,
2718
+ value => _assert_fail,
2719
+ start => 54917,
2720
+ 'end' => 54963,
2721
+ pattern_start => 54928,
2722
+ pattern_end => 54935})
2723
+ end,
2724
+ erlang:round(math:floor(case Log@1 of
2725
+ +0.0 -> +0.0;
2726
+ -0.0 -> -0.0;
2727
+ Gleam@denominator -> log_random() / Gleam@denominator
2728
+ end))
2729
+ end,
2730
+ case drop(List, Skip) of
2731
+ [] ->
2732
+ Reservoir;
2733
+
2734
+ [First | Rest] ->
2735
+ Reservoir@1 = gleam@dict:insert(
2736
+ Reservoir,
2737
+ gleam@int:random(N),
2738
+ First
2739
+ ),
2740
+ W@1 = W * math:exp(case erlang:float(N) of
2741
+ +0.0 -> +0.0;
2742
+ -0.0 -> -0.0;
2743
+ Gleam@denominator@1 -> log_random() / Gleam@denominator@1
2744
+ end),
2745
+ sample_loop(Rest, Reservoir@1, N, W@1)
2746
+ end.
2747
+
2748
+ -file("src/gleam/list.gleam", 2312).
2749
+ ?DOC(
2750
+ " Returns a random sample of up to n elements from a list using reservoir\n"
2751
+ " sampling via [Algorithm L](https://en.wikipedia.org/wiki/Reservoir_sampling#Optimal:_Algorithm_L).\n"
2752
+ " Returns an empty list if the sample size is less than or equal to 0.\n"
2753
+ "\n"
2754
+ " Order is not random, only selection is.\n"
2755
+ "\n"
2756
+ " ## Examples\n"
2757
+ "\n"
2758
+ " ```gleam\n"
2759
+ " reservoir_sample([1, 2, 3, 4, 5], 3)\n"
2760
+ " // -> [2, 4, 5] // A random sample of 3 items\n"
2761
+ " ```\n"
2762
+ ).
2763
+ -spec sample(list(ATM), integer()) -> list(ATM).
2764
+ sample(List, N) ->
2765
+ {Reservoir, Rest} = build_reservoir(List, N),
2766
+ case gleam@dict:is_empty(Reservoir) of
2767
+ true ->
2768
+ [];
2769
+
2770
+ false ->
2771
+ W = math:exp(case erlang:float(N) of
2772
+ +0.0 -> +0.0;
2773
+ -0.0 -> -0.0;
2774
+ Gleam@denominator -> log_random() / Gleam@denominator
2775
+ end),
2776
+ maps:values(sample_loop(Rest, Reservoir, N, W))
2777
+ end.
2778
+
2779
+ -file("src/gleam/list.gleam", 1814).
2780
+ -spec permutation_zip(list(AOI), list(AOI), list(list(AOI))) -> list(list(AOI)).
2781
+ permutation_zip(List, Rest, Acc) ->
2782
+ case List of
2783
+ [] ->
2784
+ lists:reverse(Acc);
2785
+
2786
+ [Head | Tail] ->
2787
+ permutation_prepend(
2788
+ Head,
2789
+ permutations(lists:reverse(Rest, Tail)),
2790
+ Tail,
2791
+ [Head | Rest],
2792
+ Acc
2793
+ )
2794
+ end.
2795
+
2796
+ -file("src/gleam/list.gleam", 1807).
2797
+ ?DOC(
2798
+ " Returns all the permutations of a list.\n"
2799
+ "\n"
2800
+ " ## Examples\n"
2801
+ "\n"
2802
+ " ```gleam\n"
2803
+ " permutations([1, 2])\n"
2804
+ " // -> [[1, 2], [2, 1]]\n"
2805
+ " ```\n"
2806
+ ).
2807
+ -spec permutations(list(AOE)) -> list(list(AOE)).
2808
+ permutations(List) ->
2809
+ case List of
2810
+ [] ->
2811
+ [[]];
2812
+
2813
+ L ->
2814
+ permutation_zip(L, [], [])
2815
+ end.
2816
+
2817
+ -file("src/gleam/list.gleam", 1832).
2818
+ -spec permutation_prepend(
2819
+ AOP,
2820
+ list(list(AOP)),
2821
+ list(AOP),
2822
+ list(AOP),
2823
+ list(list(AOP))
2824
+ ) -> list(list(AOP)).
2825
+ permutation_prepend(El, Permutations, List_1, List_2, Acc) ->
2826
+ case Permutations of
2827
+ [] ->
2828
+ permutation_zip(List_1, List_2, Acc);
2829
+
2830
+ [Head | Tail] ->
2831
+ permutation_prepend(El, Tail, List_1, List_2, [[El | Head] | Acc])
2832
+ end.