-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 Rework #80
ES6 Rework #80
Conversation
src/core.js
Outdated
} | ||
|
||
_transform(action){ | ||
return new Sequence(this._spawn, this._actions.concat([action])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using Linked List will be more efficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and maybe in other places where you are concat
ing on normal js array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. This is the only place I think. This array doesn't see much action though, that's all handled by the double ended queue in _fork.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any immutable list with fast push
you know of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know, I would have done something like this :d
const List = daggy.taggedSum('List',{
Cons: ['x','xs'],
Nil: []
})
src/core.js
Outdated
export const Next = x => new Iteration(false, x); | ||
export const Done = x => new Iteration(true, x); | ||
|
||
export const chainRec = (step, init) => (function recur(x){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it ✨
This causes JavaScript to resolve the constructor property to the root ancestor. This is exactly what we want because our root ancestor (Future) is our Type Representative.
For better code coverage reporting
Allowing any Future structure to expose information about its internal state.
Increases the performance of ChainRec by an order of magnitude, by using a specialized interpreter.
Now that this is feature-complete, I'm merging it into |
Breaking changes - #80 The ES5 import has been moved from `fluture/es5` to `fluture`. - #80 The `Future#hook` *method* (but not the function) has been removed. - #80 Old environments are asked to bring their own polyfills for `Object.create`, `Object.assign` and `Array.isArray`. - #96 The arguments to the `ap`-method have been flipped back. - #97 `and` and `or` no longer run the two Futures in parallel. - #98 `fromPromise` has been renamed to `encaseP`. New features - #80 Added an ES6 module for use with tools like [Rollup](https://rollupjs.org/). - #80 All transformations, including recursive `chain`, are now stack safe! - #80 Added `isNever`. - #80 Added aliases `attempt = try`, `go = do`, `lastly = finally`. - #98 Added `tryP`, the nullary version of `encaseP`. Bug fixes and improvements - Added fast failure to `encase` and `encaseP`. - #98 Errors thrown while transforming Futures produced by `tryP` or `encaseP` no longer get caught (and silenced) by the Promise. - #80 User-supplied functions no longer have strict arity requirements. - #80 `Future.hook` no longer cancels the acquire Future after it has settled. - #80 `Future.hook` now always cancels running Futures appropriately. - #102 Supplying incompatible or outdated instances of Fluture now throws more sensible error messages.
This painfully Object Oriented (see 6) proof of concept represents the beginning of rewriting Fluture using es6 modules, with some goals in mind:
Support tree shaking - The more code I can separate to independent chunks, the smaller
rollup
can make bundles which include Fluture.Support es5 - Fluture already had support for es5 by means of
require('fluture/es5')
, but this new version has it by default.Code minification - No objections to longer variable names
Stack safety - @safareli and I recently came upon the idea of making Future a flat data-structure, and interpret the structure in a stack safe way in
fork()
, much like howChainRec
was implemented. This allows for transforming a single Future more thann
times, wheren
is the available space in the stack.Safe chain recursion - Somewhat related to stack safety, the interpretation of a Future should also flatten recursive calls made via
chain()
into the same loop, allowing for infinite recursion without blowing the stack, or running out of memory.Keep the performance reasonable - This is the reason for the Object Orientation. V8 simply does a much better job at optimizing it.
All of the above are implemented in this proof of concept. The performance has somewhat degraded compared to the previous version, but the memory footprint has somewhat improved.
TODO
See Project 1