@grain/stdlib 0.5.3 → 0.5.4

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.
package/number.md CHANGED
@@ -17,6 +17,32 @@ import Number from "number"
17
17
 
18
18
  Number constant values.
19
19
 
20
+ ### Number.**nan**
21
+
22
+ <details disabled>
23
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
24
+ No other changes yet.
25
+ </details>
26
+
27
+ ```grain
28
+ nan : Number
29
+ ```
30
+
31
+ NaN represented as a Number value.
32
+
33
+ ### Number.**infinity**
34
+
35
+ <details disabled>
36
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
37
+ No other changes yet.
38
+ </details>
39
+
40
+ ```grain
41
+ infinity : Number
42
+ ```
43
+
44
+ Infinity represented as a Number value.
45
+
20
46
  ### Number.**pi**
21
47
 
22
48
  <details disabled>
@@ -164,6 +190,57 @@ Returns:
164
190
  |----|-----------|
165
191
  |`Number`|The quotient of the two operands|
166
192
 
193
+ ### Number.**pow**
194
+
195
+ <details disabled>
196
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
197
+ No other changes yet.
198
+ </details>
199
+
200
+ ```grain
201
+ pow : (Number, Number) -> Number
202
+ ```
203
+
204
+ Computes the exponentiation of the given base and power.
205
+
206
+ Parameters:
207
+
208
+ |param|type|description|
209
+ |-----|----|-----------|
210
+ |`base`|`Number`|The base number|
211
+ |`power`|`Number`|The exponent number|
212
+
213
+ Returns:
214
+
215
+ |type|description|
216
+ |----|-----------|
217
+ |`Number`|The base raised to the given power|
218
+
219
+ ### Number.**exp**
220
+
221
+ <details disabled>
222
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
223
+ No other changes yet.
224
+ </details>
225
+
226
+ ```grain
227
+ exp : Number -> Number
228
+ ```
229
+
230
+ Computes the exponentiation of Euler's number to the given power.
231
+
232
+ Parameters:
233
+
234
+ |param|type|description|
235
+ |-----|----|-----------|
236
+ |`power`|`Number`|The exponent number|
237
+
238
+ Returns:
239
+
240
+ |type|description|
241
+ |----|-----------|
242
+ |`Number`|The `Number.e` value raised to the given power|
243
+
167
244
  ### Number.**sqrt**
168
245
 
169
246
  <details disabled>
@@ -225,9 +302,16 @@ Number.sign(0) == 0
225
302
 
226
303
  ### Number.**min**
227
304
 
228
- <details disabled>
229
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
230
- No other changes yet.
305
+ <details>
306
+ <summary>Added in <code>0.4.0</code></summary>
307
+ <table>
308
+ <thead>
309
+ <tr><th>version</th><th>changes</th></tr>
310
+ </thead>
311
+ <tbody>
312
+ <tr><td><code>0.5.4</code></td><td>Handle NaN properly</td></tr>
313
+ </tbody>
314
+ </table>
231
315
  </details>
232
316
 
233
317
  ```grain
@@ -251,9 +335,16 @@ Returns:
251
335
 
252
336
  ### Number.**max**
253
337
 
254
- <details disabled>
255
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
256
- No other changes yet.
338
+ <details>
339
+ <summary>Added in <code>0.4.0</code></summary>
340
+ <table>
341
+ <thead>
342
+ <tr><th>version</th><th>changes</th></tr>
343
+ </thead>
344
+ <tbody>
345
+ <tr><td><code>0.5.4</code></td><td>Handle NaN properly</td></tr>
346
+ </tbody>
347
+ </table>
257
348
  </details>
258
349
 
259
350
  ```grain
@@ -277,9 +368,16 @@ Returns:
277
368
 
278
369
  ### Number.**ceil**
279
370
 
280
- <details disabled>
281
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
282
- No other changes yet.
371
+ <details>
372
+ <summary>Added in <code>0.4.0</code></summary>
373
+ <table>
374
+ <thead>
375
+ <tr><th>version</th><th>changes</th></tr>
376
+ </thead>
377
+ <tbody>
378
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity properly</td></tr>
379
+ </tbody>
380
+ </table>
283
381
  </details>
284
382
 
285
383
  ```grain
@@ -302,9 +400,16 @@ Returns:
302
400
 
303
401
  ### Number.**floor**
304
402
 
305
- <details disabled>
306
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
307
- No other changes yet.
403
+ <details>
404
+ <summary>Added in <code>0.4.0</code></summary>
405
+ <table>
406
+ <thead>
407
+ <tr><th>version</th><th>changes</th></tr>
408
+ </thead>
409
+ <tbody>
410
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity properly</td></tr>
411
+ </tbody>
412
+ </table>
308
413
  </details>
309
414
 
310
415
  ```grain
@@ -327,9 +432,16 @@ Returns:
327
432
 
328
433
  ### Number.**trunc**
329
434
 
330
- <details disabled>
331
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
332
- No other changes yet.
435
+ <details>
436
+ <summary>Added in <code>0.4.0</code></summary>
437
+ <table>
438
+ <thead>
439
+ <tr><th>version</th><th>changes</th></tr>
440
+ </thead>
441
+ <tbody>
442
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity properly</td></tr>
443
+ </tbody>
444
+ </table>
333
445
  </details>
334
446
 
335
447
  ```grain
@@ -352,9 +464,16 @@ Returns:
352
464
 
353
465
  ### Number.**round**
354
466
 
355
- <details disabled>
356
- <summary tabindex="-1">Added in <code>0.4.0</code></summary>
357
- No other changes yet.
467
+ <details>
468
+ <summary>Added in <code>0.4.0</code></summary>
469
+ <table>
470
+ <thead>
471
+ <tr><th>version</th><th>changes</th></tr>
472
+ </thead>
473
+ <tbody>
474
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity properly</td></tr>
475
+ </tbody>
476
+ </table>
358
477
  </details>
359
478
 
360
479
  ```grain
@@ -612,9 +731,16 @@ Returns:
612
731
 
613
732
  ### Number.**sin**
614
733
 
615
- <details disabled>
616
- <summary tabindex="-1">Added in <code>0.5.2</code></summary>
617
- No other changes yet.
734
+ <details>
735
+ <summary>Added in <code>0.5.2</code></summary>
736
+ <table>
737
+ <thead>
738
+ <tr><th>version</th><th>changes</th></tr>
739
+ </thead>
740
+ <tbody>
741
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity</td></tr>
742
+ </tbody>
743
+ </table>
618
744
  </details>
619
745
 
620
746
  ```grain
@@ -637,9 +763,16 @@ Returns:
637
763
 
638
764
  ### Number.**cos**
639
765
 
640
- <details disabled>
641
- <summary tabindex="-1">Added in <code>0.5.2</code></summary>
642
- No other changes yet.
766
+ <details>
767
+ <summary>Added in <code>0.5.2</code></summary>
768
+ <table>
769
+ <thead>
770
+ <tr><th>version</th><th>changes</th></tr>
771
+ </thead>
772
+ <tbody>
773
+ <tr><td><code>0.5.4</code></td><td>Handle NaN and Infinity</td></tr>
774
+ </tbody>
775
+ </table>
643
776
  </details>
644
777
 
645
778
  ```grain
@@ -660,3 +793,130 @@ Returns:
660
793
  |----|-----------|
661
794
  |`Number`|The computed cosine|
662
795
 
796
+ ### Number.**tan**
797
+
798
+ <details disabled>
799
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
800
+ No other changes yet.
801
+ </details>
802
+
803
+ ```grain
804
+ tan : Number -> Number
805
+ ```
806
+
807
+ Computes the tangent of a number (in radians) using Chebyshev polynomials.
808
+
809
+ Parameters:
810
+
811
+ |param|type|description|
812
+ |-----|----|-----------|
813
+ |`radians`|`Number`|The input in radians|
814
+
815
+ Returns:
816
+
817
+ |type|description|
818
+ |----|-----------|
819
+ |`Number`|The computed tangent|
820
+
821
+ ### Number.**gamma**
822
+
823
+ <details disabled>
824
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
825
+ No other changes yet.
826
+ </details>
827
+
828
+ ```grain
829
+ gamma : Number -> Number
830
+ ```
831
+
832
+ Computes the gamma function of a value using Lanczos approximation.
833
+ Fails when the given value is zero.
834
+
835
+ Parameters:
836
+
837
+ |param|type|description|
838
+ |-----|----|-----------|
839
+ |`z`|`Number`|The value to interpolate|
840
+
841
+ Returns:
842
+
843
+ |type|description|
844
+ |----|-----------|
845
+ |`Number`|The gamma of the given value|
846
+
847
+ ### Number.**factorial**
848
+
849
+ <details disabled>
850
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
851
+ No other changes yet.
852
+ </details>
853
+
854
+ ```grain
855
+ factorial : Number -> Number
856
+ ```
857
+
858
+ Computes the product of consecutive integers for an integer input and computes the gamma function for non-integer inputs.
859
+ Fails if the input is a negative number.
860
+
861
+ Parameters:
862
+
863
+ |param|type|description|
864
+ |-----|----|-----------|
865
+ |`n`|`Number`|The value to factorialize|
866
+
867
+ Returns:
868
+
869
+ |type|description|
870
+ |----|-----------|
871
+ |`Number`|The factorial of the given value|
872
+
873
+ ### Number.**toRadians**
874
+
875
+ <details disabled>
876
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
877
+ No other changes yet.
878
+ </details>
879
+
880
+ ```grain
881
+ toRadians : Number -> Number
882
+ ```
883
+
884
+ Converts degrees to radians.
885
+
886
+ Parameters:
887
+
888
+ |param|type|description|
889
+ |-----|----|-----------|
890
+ |`degrees`|`Number`|The value to convert|
891
+
892
+ Returns:
893
+
894
+ |type|description|
895
+ |----|-----------|
896
+ |`Number`|The value in radians|
897
+
898
+ ### Number.**toDegrees**
899
+
900
+ <details disabled>
901
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
902
+ No other changes yet.
903
+ </details>
904
+
905
+ ```grain
906
+ toDegrees : Number -> Number
907
+ ```
908
+
909
+ Converts radians to degrees.
910
+
911
+ Parameters:
912
+
913
+ |param|type|description|
914
+ |-----|----|-----------|
915
+ |`radians`|`Number`|The value to convert|
916
+
917
+ Returns:
918
+
919
+ |type|description|
920
+ |----|-----------|
921
+ |`Number`|The value in degrees|
922
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grain/stdlib",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "The standard library for the Grain language.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://grain-lang.org",
package/priorityqueue.gr CHANGED
@@ -219,6 +219,29 @@ export let drain = pq => {
219
219
  List.reverse(drainRec([]))
220
220
  }
221
221
 
222
+ /**
223
+ * Constructs a new priority queue initialized with the elements in the array
224
+ * using a custom comparator function, which is used to determine priority of
225
+ * elements. The comparator function takes two elements and must return 0 if
226
+ * both share priority, a positive number if the first has greater priority,
227
+ * and a negative number if the first has less priority.
228
+ *
229
+ * @param array: An array of values used to initialize the priority queue
230
+ * @param comp: A comparator function used to assign priority to elements
231
+ * @returns A priority queue containing the elements from the array
232
+ *
233
+ * @since v0.5.4
234
+ */
235
+ export let fromArray = (array, comp) => {
236
+ let size = Array.length(array)
237
+ let array = Array.map(x => Some(x), array)
238
+ let heap = { size, array, comp }
239
+ for (let mut i = size - 1; i >= 0; i -= 1) {
240
+ siftDown(i, heap)
241
+ }
242
+ heap
243
+ }
244
+
222
245
  /**
223
246
  * Constructs a new priority queue initialized with the elements in the list
224
247
  * using a custom comparator function, which is used to determine priority of
@@ -233,9 +256,6 @@ export let drain = pq => {
233
256
  * @since v0.5.3
234
257
  */
235
258
  export let fromList = (list, comp) => {
236
- let heap = makeSized(List.length(list), comp)
237
- List.forEach(val => {
238
- push(val, heap)
239
- }, list)
240
- heap
259
+ let array = Array.fromList(list)
260
+ fromArray(array, comp)
241
261
  }
package/priorityqueue.md CHANGED
@@ -247,6 +247,36 @@ Returns:
247
247
  |----|-----------|
248
248
  |`List<a>`|A list of all elements in the priority in priority order|
249
249
 
250
+ ### PriorityQueue.**fromArray**
251
+
252
+ <details disabled>
253
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
254
+ No other changes yet.
255
+ </details>
256
+
257
+ ```grain
258
+ fromArray : (Array<a>, ((a, a) -> Number)) -> PriorityQueue<a>
259
+ ```
260
+
261
+ Constructs a new priority queue initialized with the elements in the array
262
+ using a custom comparator function, which is used to determine priority of
263
+ elements. The comparator function takes two elements and must return 0 if
264
+ both share priority, a positive number if the first has greater priority,
265
+ and a negative number if the first has less priority.
266
+
267
+ Parameters:
268
+
269
+ |param|type|description|
270
+ |-----|----|-----------|
271
+ |`array`|`Array<a>`|An array of values used to initialize the priority queue|
272
+ |`comp`|`(a, a) -> Number`|A comparator function used to assign priority to elements|
273
+
274
+ Returns:
275
+
276
+ |type|description|
277
+ |----|-----------|
278
+ |`PriorityQueue<a>`|A priority queue containing the elements from the array|
279
+
250
280
  ### PriorityQueue.**fromList**
251
281
 
252
282
  <details disabled>
package/queue.gr CHANGED
@@ -15,13 +15,26 @@ record Queue<a> {
15
15
  }
16
16
 
17
17
  /**
18
- * @section Values: Functions for working with queues.
18
+ * @section Values: Functions and constants for working with queues.
19
19
  */
20
20
 
21
+ /**
22
+ * An empty queue.
23
+ *
24
+ * @since v0.5.4
25
+ */
26
+ export let empty = {
27
+ let empty = { forwards: [], backwards: [] }
28
+ empty
29
+ }
30
+
21
31
  /**
22
32
  * Creates an empty queue.
23
33
  *
24
34
  * @returns An empty queue
35
+ *
36
+ * @deprecated This will be removed in the v0.6.0 release of Grain.
37
+ *
25
38
  * @since v0.2.0
26
39
  */
27
40
  export let make = () => {
package/queue.md CHANGED
@@ -25,10 +25,25 @@ type Queue<a>
25
25
 
26
26
  ## Values
27
27
 
28
- Functions for working with queues.
28
+ Functions and constants for working with queues.
29
+
30
+ ### Queue.**empty**
31
+
32
+ <details disabled>
33
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
34
+ No other changes yet.
35
+ </details>
36
+
37
+ ```grain
38
+ empty : Queue<a>
39
+ ```
40
+
41
+ An empty queue.
29
42
 
30
43
  ### Queue.**make**
31
44
 
45
+ > **Deprecated:** This will be removed in the v0.6.0 release of Grain.
46
+
32
47
  <details disabled>
33
48
  <summary tabindex="-1">Added in <code>0.2.0</code></summary>
34
49
  No other changes yet.