functionalscript 0.0.349 → 0.0.352

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/LANGUAGE.md CHANGED
@@ -206,3 +206,43 @@ const f = () => x // < invalid
206
206
  ### 9.7. Block
207
207
 
208
208
  [Block](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)
209
+
210
+ ## 10. Generators
211
+
212
+ For compatibility reason, FunctionalScript allows to create generators as implementation of `[Symbol.iterator]` function. However, it doesn't allow to read the `[Symbol.iterator]` property. For example
213
+
214
+ This code is allowed
215
+
216
+ ```js
217
+ /** @type {<T>(list: List<T>) => Iterable<T>} */
218
+ const iterable = list => ({
219
+ *[Symbol.iterator]() {
220
+ let i = list
221
+ while (true) {
222
+ const r = next(i)
223
+ if (r === undefined) { return }
224
+ yield r.first
225
+ i = r.tail
226
+ }
227
+ }
228
+ })
229
+ ```
230
+
231
+ The following code is not allowed, because `iterator` is a mutated object by design in JavaScript.
232
+
233
+ ```js
234
+ const it = [0, 1, 2][Symbol.iterator] //< compilation error.
235
+ ```
236
+
237
+ Use `Iterable` instead of `Iterator`.
238
+
239
+ ```js
240
+ const x = () => {
241
+ const a = [0, 1, 2] // iterable
242
+ let sum = 0;
243
+ for (let i in a) {
244
+ sum = sum + i
245
+ }
246
+ return sum;
247
+ }
248
+ ```
package/com/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # COM (Component Object Model)
2
+
3
+ Basic Types: `f32`, `f64`, `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `usize`, `isize`, `bool`, ``.
package/com/main.f.js ADDED
@@ -0,0 +1,30 @@
1
+ /** @typedef {{readonly[k in string]: Definition}} Library */
2
+
3
+ /** @typedef {Struct|Interface} Definition */
4
+
5
+ /** @typedef {{readonly struct: FieldArray}} Struct */
6
+
7
+ /** @typedef {readonly Field[]} FieldArray */
8
+
9
+ /** @typedef {[string, Type]} Field */
10
+
11
+ /**
12
+ * @typedef {{
13
+ * readonly interface: MethodArray
14
+ * readonly guid: string
15
+ * }} Interface
16
+ */
17
+
18
+ /** @typedef {readonly Method[]} MethodArray */
19
+
20
+ /** @typedef {readonly[string, FieldArray, Type]} Method */
21
+
22
+ /** @typedef {BaseType|Id|Pointer} Type */
23
+
24
+ /** @typedef {readonly[string]} Id */
25
+
26
+ /** @typedef {'u8'|'i8'|'u16'|'i16'|'u32'|'i32'|'u64'|'i64'|'usize'|'isize'|'f32'|'f64'|'bool'|''} BaseType */
27
+
28
+ /** @typedef {{readonly '*': Type}} Pointer */
29
+
30
+ module.exports = {}
package/com/test.f.js ADDED
@@ -0,0 +1,23 @@
1
+ const _ = require('./main.f.js')
2
+
3
+ /** @type {_.Library} */
4
+ const library = {
5
+ Slice: {
6
+ struct: [
7
+ ['Start', { '*': 'u8' }],
8
+ ['End', 'usize'],
9
+ ]
10
+ },
11
+ IMy: {
12
+ guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
13
+ interface: [
14
+ ['GetSlice', [], ['Slice']],
15
+ ['SetSlice',
16
+ [['slice', ['Slice']]],
17
+ ''
18
+ ],
19
+ ],
20
+ }
21
+ }
22
+
23
+ module.exports = {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Package
4
4
 
5
- [package/index.js](package/index.js)
5
+ [package/main.f.js](package/main.f.js)
6
6
 
7
7
  ```ts
8
8
  // A dictionary of packages.
@@ -31,7 +31,7 @@ type Package = {
31
31
 
32
32
  ## Module
33
33
 
34
- [module/index.js](module/index.js)
34
+ [module/main.f.js](module/main.f.js)
35
35
 
36
36
  ```ts
37
37
  // A module map is a dictionary of modules.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.349",
3
+ "version": "0.0.352",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "main.f.js",
6
6
  "scripts": {
package/test.f.js CHANGED
@@ -16,6 +16,7 @@ require('./types/stringset/test.f.js')
16
16
  require('./commonjs/build/test.f.js')
17
17
  require('./types/range/test.f.js')
18
18
  require('./html/test.f.js')
19
+ require('./text/test.f.js')
19
20
 
20
21
  /** @type {() => never} */
21
22
  const assert = () => { throw 'assert' }
package/text/main.f.js ADDED
@@ -0,0 +1,21 @@
1
+ const list = require('../types/list/main.f.js')
2
+
3
+ /** @typedef {readonly Item[]} Text */
4
+
5
+ /** @typedef {string|Text} Item */
6
+
7
+ /** @type {(indent: string) => (text: Text) => list.List<string>} */
8
+ const flat = indent => {
9
+ /** @type {(v: string) => string} */
10
+ const indentFn = v => `${indent}${v}`
11
+ const map = list.map(indentFn)
12
+ /** @type {(item: Item) => list.List<string>} */
13
+ const flatItem = item => typeof(item) === 'string' ? [item] : map(flatText(item))
14
+ const flatText = list.flatMap(flatItem)
15
+ return flatText
16
+ }
17
+
18
+ module.exports = {
19
+ /** @readonly */
20
+ flat,
21
+ }
package/text/test.f.js ADDED
@@ -0,0 +1,18 @@
1
+ const _ = require('./main.f.js')
2
+ const list = require('../types/list/main.f.js')
3
+
4
+ {
5
+ /** @type {_.Text} */
6
+ const text = [
7
+ 'a',
8
+ 'b',
9
+ [
10
+ 'c',
11
+ ['d'],
12
+ ]
13
+ ]
14
+ const result = list.join('\n')(_.flat('_')(text))
15
+ if (result !== 'a\nb\n_c\n__d') { throw result }
16
+ }
17
+
18
+ module.exports = {}