functionalscript 0.0.212 → 0.0.214

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.212",
3
+ "version": "0.0.214",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/sequence/index.js CHANGED
@@ -265,6 +265,21 @@ const zip = a => b => () => {
265
265
  return [[resultA[0], resultB[0]], zip(resultA[1])(resultB[1])]
266
266
  }
267
267
 
268
+ /** @type {<T>(s: Sequence<T>) => Sequence<T>} */
269
+ const reverse = s => {
270
+ /** @type {typeof s} */
271
+ let iResult = empty
272
+ let iSource = s
273
+ while (true) {
274
+ const result = next(iSource)
275
+ if (result === undefined) { return iResult }
276
+ /** @type {typeof s} */
277
+ const old = iResult
278
+ iResult = () => [result[0], old]
279
+ iSource = result[1]
280
+ }
281
+ }
282
+
268
283
  module.exports = {
269
284
  /** @readonly */
270
285
  next,
@@ -326,4 +341,6 @@ module.exports = {
326
341
  includes,
327
342
  /** @readonly */
328
343
  zip,
344
+ /** @readonly */
345
+ reverse,
329
346
  }
package/sequence/test.js CHANGED
@@ -1,6 +1,8 @@
1
1
  const seq = require('.')
2
2
  const { sum } = require('./operator')
3
3
  const array = require('./array')
4
+ const json = require('../json')
5
+ const { id } = require('../function')
4
6
 
5
7
  /** @type {<T>(input: seq.Sequence<T>) => void} */
6
8
  const print = input => {
@@ -63,3 +65,10 @@ const print = input => {
63
65
  const x = seq.join(':')(seq.list("1", "2", "3", "4", "5", "6"))
64
66
  if (x !== "1:2:3:4:5:6") { throw x }
65
67
  }
68
+
69
+ {
70
+ const r = seq.reverse(seq.list(1, 2, 3, 4))
71
+ const s = array.fromSequence(r)
72
+ const j = json.stringify(id)(s)
73
+ if (j !== '[4,3,2,1]') { throw j }
74
+ }