@grain/stdlib 0.7.0 → 0.7.2

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 (62) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/array.md +491 -491
  3. package/bigint.md +198 -198
  4. package/buffer.gr +66 -1
  5. package/buffer.md +395 -272
  6. package/bytes.gr +1 -0
  7. package/bytes.md +200 -199
  8. package/char.md +125 -125
  9. package/exception.md +9 -9
  10. package/float32.md +195 -195
  11. package/float64.md +195 -195
  12. package/fs.md +115 -115
  13. package/hash.md +16 -16
  14. package/int16.md +155 -155
  15. package/int32.gr +1 -1
  16. package/int32.md +207 -207
  17. package/int64.gr +1 -1
  18. package/int64.md +207 -207
  19. package/int8.md +155 -155
  20. package/json.md +59 -59
  21. package/list.md +347 -347
  22. package/map.md +222 -222
  23. package/marshal.md +12 -12
  24. package/number.gr +119 -5
  25. package/number.md +503 -261
  26. package/option.md +141 -141
  27. package/package.json +2 -2
  28. package/path.gr +82 -65
  29. package/path.md +210 -141
  30. package/pervasives.md +238 -238
  31. package/priorityqueue.md +112 -112
  32. package/queue.md +117 -117
  33. package/random.md +37 -37
  34. package/range.md +36 -36
  35. package/rational.md +107 -107
  36. package/regex.md +91 -91
  37. package/result.md +102 -102
  38. package/runtime/atof/decimal.md +6 -6
  39. package/runtime/compare.md +7 -7
  40. package/runtime/dataStructures.md +178 -178
  41. package/runtime/equal.md +7 -7
  42. package/runtime/exception.md +15 -15
  43. package/runtime/malloc.md +9 -9
  44. package/runtime/numbers.md +269 -269
  45. package/runtime/string.md +17 -17
  46. package/runtime/unsafe/conv.md +6 -6
  47. package/runtime/unsafe/memory.gr +2 -19
  48. package/runtime/unsafe/memory.md +10 -10
  49. package/runtime/utf8.md +31 -31
  50. package/runtime/wasi.md +9 -9
  51. package/set.md +211 -211
  52. package/stack.md +122 -122
  53. package/string.md +228 -228
  54. package/uint16.md +148 -148
  55. package/uint32.md +192 -192
  56. package/uint64.md +192 -192
  57. package/uint8.md +148 -148
  58. package/uri.md +77 -77
  59. package/wasi/file.md +269 -269
  60. package/wasi/process.md +21 -21
  61. package/wasi/random.md +9 -9
  62. package/wasi/time.md +12 -12
package/path.gr CHANGED
@@ -17,6 +17,7 @@
17
17
  * - The path segment `.` indicates the relative "current" directory of a path, and `..` indicates the parent directory of a path
18
18
  *
19
19
  * @example from "path" include Path
20
+ * @example let p = Path.fromString("./tmp/file.txt")
20
21
  *
21
22
  * @since v0.5.5
22
23
  */
@@ -88,49 +89,53 @@ and record TBase<a> {
88
89
  }
89
90
  /**
90
91
  * Represents an absolute path's anchor point.
92
+ *
93
+ * @since v0.5.5
91
94
  */
92
95
  and provide enum AbsoluteRoot {
93
96
  Root,
94
97
  Drive(Char),
95
98
  }
96
99
 
97
- // Dummy record names put here just to distinguish the two. These could be
98
- // replaced with opaque types if they get added to the language
99
100
  /**
100
101
  * Represents a relative path.
102
+ *
103
+ * @since v0.5.5
101
104
  */
102
- abstract record Relative {
103
- _rel: Void,
104
- }
105
+ abstract type Relative = Void
105
106
 
106
107
  /**
107
108
  * Represents an absolute path.
109
+ *
110
+ * @since v0.5.5
108
111
  */
109
- abstract record Absolute {
110
- _abs: Void,
111
- }
112
+ abstract type Absolute = Void
112
113
 
113
114
  /**
114
115
  * Represents a path referencing a file.
116
+ *
117
+ * @since v0.5.5
115
118
  */
116
- abstract record File {
117
- _file: Void,
118
- }
119
+ abstract type File = Void
119
120
 
120
121
  /**
121
122
  * Represents a path referencing a directory.
123
+ *
124
+ * @since v0.5.5
122
125
  */
123
- abstract record Directory {
124
- _directory: Void,
125
- }
126
+ abstract type Directory = Void
126
127
 
127
128
  /**
128
129
  * Represents a path typed on (`Absolute` or `Relative`) and (`File` or
129
130
  * `Directory`)
131
+ *
132
+ * @since v0.5.5
130
133
  */
131
134
  abstract type rec TypedPath<a, b> = (TBase<a>, TFileType<b>, List<String>)
132
135
  /**
133
136
  * Represents a system path.
137
+ *
138
+ * @since v0.5.5
134
139
  */
135
140
  and provide enum Path {
136
141
  AbsoluteFile(TypedPath<Absolute, File>),
@@ -141,6 +146,8 @@ and provide enum Path {
141
146
 
142
147
  /**
143
148
  * Represents a platform-specific path encoding scheme.
149
+ *
150
+ * @since v0.5.5
144
151
  */
145
152
  provide enum Platform {
146
153
  Windows,
@@ -149,6 +156,8 @@ provide enum Platform {
149
156
 
150
157
  /**
151
158
  * Represents an error that can occur when finding a property of a path.
159
+ *
160
+ * @since v0.5.5
152
161
  */
153
162
  provide enum PathOperationError {
154
163
  IncompatiblePathType,
@@ -156,6 +165,8 @@ provide enum PathOperationError {
156
165
 
157
166
  /**
158
167
  * Represents an error that can occur when appending paths.
168
+ *
169
+ * @since v0.5.5
159
170
  */
160
171
  provide enum AppendError {
161
172
  AppendToFile,
@@ -164,6 +175,8 @@ provide enum AppendError {
164
175
 
165
176
  /**
166
177
  * Represents the status of an ancestry check between two paths.
178
+ *
179
+ * @since v0.5.5
167
180
  */
168
181
  provide enum AncestryStatus {
169
182
  Descendant,
@@ -175,6 +188,8 @@ provide enum AncestryStatus {
175
188
  /**
176
189
  * Represents an error that can occur when the types of paths are incompatible
177
190
  * for an operation.
191
+ *
192
+ * @since v0.5.5
178
193
  */
179
194
  provide enum IncompatibilityError {
180
195
  DifferentRoots,
@@ -183,6 +198,8 @@ provide enum IncompatibilityError {
183
198
 
184
199
  /**
185
200
  * Represents possible errors for the `relativeTo` operation.
201
+ *
202
+ * @since v0.5.5
186
203
  */
187
204
  provide enum RelativizationError {
188
205
  Incompatible(IncompatibilityError),
@@ -375,10 +392,10 @@ let fromStringHelper = (pathStr, platform) => {
375
392
  * @param platform: The platform whose path separators should be used for parsing
376
393
  * @returns The path wrapped with details encoded within the type
377
394
  *
378
- * @example fromString("file.txt") // a relative Path referencing the file ./file.txt
379
- * @example fromString(".") // a relative Path referencing the current directory
380
- * @example fromString("/bin/", Posix) // an absolute Path referencing the directory /bin/
381
- * @example fromString("C:\\file.txt", Windows) // a relative Path referencing the file C:\file.txt
395
+ * @example Path.fromString("file.txt") // a relative Path referencing the file ./file.txt
396
+ * @example Path.fromString(".") // a relative Path referencing the current directory
397
+ * @example Path.fromString("/bin/", Path.Posix) // an absolute Path referencing the directory /bin/
398
+ * @example Path.fromString("C:\\file.txt", Path.Windows) // a relative Path referencing the file C:\file.txt
382
399
  *
383
400
  * @since v0.5.5
384
401
  * @history v0.6.0: Merged with `fromPlatformString`; modified signature to accept platform
@@ -423,9 +440,9 @@ let toStringHelper = (path, platform) => {
423
440
  * @param platform: The `Platform` to use to represent the path as a string
424
441
  * @returns A string representing the given path
425
442
  *
426
- * @example toString(fromString("/file.txt")) == "/file.txt"
427
- * @example toString(fromString("dir/"), Posix) == "./dir/"
428
- * @example toString(fromString("C:/file.txt"), Windows) == "C:\\file.txt"
443
+ * @example Path.toString(Path.fromString("/file.txt")) == "/file.txt"
444
+ * @example Path.toString(Path.fromString("dir/"), Path.Posix) == "./dir/"
445
+ * @example Path.toString(Path.fromString("C:/file.txt"), Path.Windows) == "C:\\file.txt"
429
446
  *
430
447
  * @since v0.5.5
431
448
  * @history v0.6.0: Merged with `toPlatformString`; modified signature to accept platform
@@ -440,8 +457,8 @@ provide let toString = (path, platform=Posix) => {
440
457
  * @param path: The path to inspect
441
458
  * @returns `true` if the path is a directory path or `false` otherwise
442
459
  *
443
- * @example isDirectory(fromString("file.txt")) == false
444
- * @example isDirectory(fromString("/bin/")) == true
460
+ * @example Path.isDirectory(Path.fromString("file.txt")) == false
461
+ * @example Path.isDirectory(Path.fromString("/bin/")) == true
445
462
  *
446
463
  * @since v0.5.5
447
464
  */
@@ -456,8 +473,8 @@ provide let isDirectory = path => {
456
473
  * @param path: The path to inspect
457
474
  * @returns `true` if the path is absolute or `false` otherwise
458
475
  *
459
- * @example isAbsolute(fromString("/Users/me")) == true
460
- * @example isAbsolute(fromString("./file.txt")) == false
476
+ * @example Path.isAbsolute(Path.fromString("/Users/me")) == true
477
+ * @example Path.isAbsolute(Path.fromString("./file.txt")) == false
461
478
  */
462
479
  provide let isAbsolute = path => {
463
480
  let (base, _, _) = pathInfo(path)
@@ -490,9 +507,9 @@ let rec appendHelper = (path: PathInfo, toAppend: PathInfo) =>
490
507
  * @param toAppend: The relative path to append
491
508
  * @returns `Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible
492
509
  *
493
- * @example append(fromString("./dir/"), fromString("file.txt")) == Ok(fromString("./dir/file.txt"))
494
- * @example append(fromString("a.txt"), fromString("b.sh")) == Err(AppendToFile) // cannot append to file path
495
- * @example append(fromString("./dir/"), fromString("/dir2")) == Err(AppendAbsolute) // cannot append an absolute path
510
+ * @example Path.append(Path.fromString("./dir/"), Path.fromString("file.txt")) == Ok(Path.fromString("./dir/file.txt"))
511
+ * @example Path.append(Path.fromString("a.txt"), Path.fromString("b.sh")) == Err(Path.AppendToFile) // cannot append to file path
512
+ * @example Path.append(Path.fromString("./dir/"), Path.fromString("/dir2")) == Err(Path.AppendAbsolute) // cannot append an absolute path
496
513
  *
497
514
  * @since v0.5.5
498
515
  */
@@ -547,21 +564,21 @@ let relativeToHelper = (source: PathInfo, dest: PathInfo) => {
547
564
  * path from the source path.
548
565
  *
549
566
  * If the source and destination are incompatible in their bases, the result
550
- * will be `Err(IncompatibilityError)`.
567
+ * will be `Err(Path.IncompatibilityError)`.
551
568
  *
552
569
  * If the route to the destination cannot be concretely determined from the
553
- * source, the result will be `Err(ImpossibleRelativization)`.
570
+ * source, the result will be `Err(Path.ImpossibleRelativization)`.
554
571
  *
555
572
  * @param source: The source path
556
573
  * @param dest: The destination path to resolve
557
574
  * @returns `Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise
558
575
  *
559
- * @example relativeTo(fromString("/usr"), fromString("/usr/bin")) == Ok(fromString("./bin"))
560
- * @example relativeTo(fromString("/home/me"), fromString("/home/me")) == Ok(fromString("."))
561
- * @example relativeTo(fromString("/file.txt"), fromString("/etc/")) == Ok(fromString("../etc/"))
562
- * @example relativeTo(fromString(".."), fromString("../../thing")) Ok(fromString("../thing"))
563
- * @example relativeTo(fromString("/usr/bin"), fromString("C:/Users")) == Err(Incompatible(DifferentRoots))
564
- * @example relativeTo(fromString("../here"), fromString("./there")) == Err(ImpossibleRelativization)
576
+ * @example Path.relativeTo(Path.fromString("/usr"), Path.fromString("/usr/bin")) == Ok(Path.fromString("./bin"))
577
+ * @example Path.relativeTo(Path.fromString("/home/me"), Path.fromString("/home/me")) == Ok(Path.fromString("."))
578
+ * @example Path.relativeTo(Path.fromString("/file.txt"), Path.fromString("/etc/")) == Ok(Path.fromString("../etc/"))
579
+ * @example Path.relativeTo(Path.fromString(".."), Path.fromString("../../thing")) Ok(Path.fromString("../thing"))
580
+ * @example Path.relativeTo(Path.fromString("/usr/bin"), Path.fromString("C:/Users")) == Err(Path.Incompatible(Path.DifferentRoots))
581
+ * @example Path.relativeTo(Path.fromString("../here"), Path.fromString("./there")) == Err(Path.ImpossibleRelativization)
565
582
  *
566
583
  * @since v0.5.5
567
584
  */
@@ -595,16 +612,16 @@ let ancestryHelper = (base: PathInfo, path: PathInfo) => {
595
612
  }
596
613
 
597
614
  /**
598
- * Determines the relative ancestry betwen two paths.
615
+ * Determines the relative ancestry between two paths.
599
616
  *
600
617
  * @param base: The first path to consider
601
618
  * @param path: The second path to consider
602
619
  * @returns `Ok(ancestryStatus)` with the relative ancestry between the paths if they are compatible or `Err(err)` if they are incompatible
603
620
  *
604
- * @example ancestry(fromString("/usr"), fromString("/usr/bin/bash")) == Ok(Ancestor)
605
- * @example ancestry(fromString("/Users/me"), fromString("/Users")) == Ok(Descendant)
606
- * @example ancestry(fromString("/usr"), fromString("/etc")) == Ok(Neither)
607
- * @example ancestry(fromString("C:/dir1"), fromString("/dir2")) == Err(DifferentRoots)
621
+ * @example Path.ancestry(Path.fromString("/usr"), Path.fromString("/usr/bin/bash")) == Ok(Path.Ancestor)
622
+ * @example Path.ancestry(Path.fromString("/Users/me"), Path.fromString("/Users")) == Ok(Path.Descendant)
623
+ * @example Path.ancestry(Path.fromString("/usr"), Path.fromString("/etc")) == Ok(Path.Neither)
624
+ * @example Path.ancestry(Path.fromString("C:/dir1"), Path.fromString("/dir2")) == Err(Path.DifferentRoots)
608
625
  *
609
626
  * @since v0.5.5
610
627
  */
@@ -631,8 +648,8 @@ let parentHelper = (path: PathInfo) => match (path) {
631
648
  * @param path: The path to inspect
632
649
  * @returns A path corresponding to the parent directory of the given path
633
650
  *
634
- * @example parent(fromString("./dir/inner")) == fromString("./dir/")
635
- * @example parent(fromString("/")) == fromString("/")
651
+ * @example Path.parent(Path.fromString("./dir/inner")) == Path.fromString("./dir/")
652
+ * @example Path.parent(Path.fromString("/")) == Path.fromString("/")
636
653
  *
637
654
  * @since v0.5.5
638
655
  */
@@ -651,8 +668,8 @@ let basenameHelper = (path: PathInfo) => match (path) {
651
668
  * @param path: The path to inspect
652
669
  * @returns `Some(path)` containing the basename of the path or `None` if the path does not have one
653
670
  *
654
- * @example basename(fromString("./dir/file.txt")) == Some("file.txt")
655
- * @example basename(fromString(".."))) == None
671
+ * @example Path.basename(Path.fromString("./dir/file.txt")) == Some("file.txt")
672
+ * @example Path.basename(Path.fromString(".."))) == None
656
673
  *
657
674
  * @since v0.5.5
658
675
  */
@@ -682,10 +699,10 @@ let stemExtHelper = (path: PathInfo) => match (path) {
682
699
  * @param path: The path to inspect
683
700
  * @returns `Ok(path)` containing the stem of the file path or `Err(err)` if the path is a directory path
684
701
  *
685
- * @example stem(fromString("file.txt")) == Ok("file")
686
- * @example stem(fromString(".gitignore")) == Ok(".gitignore")
687
- * @example stem(fromString(".a.tar.gz")) == Ok(".a")
688
- * @example stem(fromString("/dir/")) == Err(IncompatiblePathType) // can only take stem of a file path
702
+ * @example Path.stem(Path.fromString("file.txt")) == Ok("file")
703
+ * @example Path.stem(Path.fromString(".gitignore")) == Ok(".gitignore")
704
+ * @example Path.stem(Path.fromString(".a.tar.gz")) == Ok(".a")
705
+ * @example Path.stem(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take stem of a file path
689
706
  *
690
707
  * @since v0.5.5
691
708
  */
@@ -705,10 +722,10 @@ provide let stem = (path: Path) => {
705
722
  * @param path: The path to inspect
706
723
  * @returns `Ok(path)` containing the extension of the file path or `Err(err)` if the path is a directory path
707
724
  *
708
- * @example extension(fromString("file.txt")) == Ok(".txt")
709
- * @example extension(fromString(".gitignore")) == Ok("")
710
- * @example extension(fromString(".a.tar.gz")) == Ok(".tar.gz")
711
- * @example extension(fromString("/dir/")) == Err(IncompatiblePathType) // can only take extension of a file path
725
+ * @example Path.extension(Path.fromString("file.txt")) == Ok(".txt")
726
+ * @example Path.extension(Path.fromString(".gitignore")) == Ok("")
727
+ * @example Path.extension(Path.fromString(".a.tar.gz")) == Ok(".tar.gz")
728
+ * @example Path.extension(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take extension of a file path
712
729
  *
713
730
  * @since v0.5.5
714
731
  */
@@ -728,10 +745,10 @@ provide let extension = (path: Path) => {
728
745
  * @param path: The path to modify
729
746
  * @returns The path with the extension removed
730
747
  *
731
- * @example removeExtension(fromString("file.txt")) == fromString("file")
732
- * @example removeExtension(fromString(".gitignore")) == fromString(".gitignore")
733
- * @example removeExtension(fromString("./dir/file")) == fromString("dir/file")
734
- * @example removeExtension(fromString("./dir/")) == fromString("dir/")
748
+ * @example Path.removeExtension(Path.fromString("file.txt")) == Path.fromString("file")
749
+ * @example Path.removeExtension(Path.fromString(".gitignore")) == Path.fromString(".gitignore")
750
+ * @example Path.removeExtension(Path.fromString("./dir/file")) == Path.fromString("dir/file")
751
+ * @example Path.removeExtension(Path.fromString("./dir/")) == Path.fromString("dir/")
735
752
  *
736
753
  * @since v7.0.0
737
754
  */
@@ -752,11 +769,11 @@ provide let removeExtension = (path: Path) => {
752
769
  * @param extension: The new extension
753
770
  * @returns The modified path
754
771
  *
755
- * @example updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
756
- * @example updateExtension(fromString("file.txt"), "") == fromString("file.")
757
- * @example updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
758
- * @example updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
759
- * @example updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
772
+ * @example Path.updateExtension(Path.fromString("file.txt"), "ext") == Path.fromString("file.ext")
773
+ * @example Path.updateExtension(Path.fromString("file.txt"), "") == Path.fromString("file.")
774
+ * @example Path.updateExtension(Path.fromString(".gitignore"), "ext") == Path.fromString(".gitignore.ext")
775
+ * @example Path.updateExtension(Path.fromString("./dir/file"), "ext") == Path.fromString("dir/file.ext")
776
+ * @example Path.updateExtension(Path.fromString("./dir/"), "ext") == Path.fromString("dir/")
760
777
  *
761
778
  * @since v7.0.0
762
779
  */
@@ -782,9 +799,9 @@ let rootHelper = (path: PathInfo) => match (path) {
782
799
  * @param path: The path to inspect
783
800
  * @returns `Ok(root)` containing the root of the path or `Err(err)` if the path is a relative path
784
801
  *
785
- * @example root(fromString("C:/Users/me/")) == Ok(Drive('C'))
786
- * @example root(fromString("/home/me/")) == Ok(Root)
787
- * @example root(fromString("./file.txt")) == Err(IncompatiblePathType)
802
+ * @example Path.root(Path.fromString("C:/Users/me/")) == Ok(Path.Drive('C'))
803
+ * @example Path.root(Path.fromString("/home/me/")) == Ok(Path.Root)
804
+ * @example Path.root(Path.fromString("./file.txt")) == Err(Path.IncompatiblePathType)
788
805
  *
789
806
  * @since v0.5.5
790
807
  */