Skip to content
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

Merged
merged 33 commits into from
Apr 13, 2017
Merged

ES6 Rework #80

merged 33 commits into from
Apr 13, 2017

Conversation

Avaq
Copy link
Member

@Avaq Avaq commented Mar 31, 2017

This painfully Object Oriented (see 6) proof of concept represents the beginning of rewriting Fluture using es6 modules, with some goals in mind:

  1. Support tree shaking - The more code I can separate to independent chunks, the smaller rollup can make bundles which include Fluture.

  2. Support es5 - Fluture already had support for es5 by means of require('fluture/es5'), but this new version has it by default.

  3. Code minification - No objections to longer variable names

  4. 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 how ChainRec was implemented. This allows for transforming a single Future more than n times, where n is the available space in the stack.

  5. 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.

  6. 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

src/core.js Outdated
}

_transform(action){
return new Sequence(this._spawn, this._actions.concat([action]));
Copy link

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

Copy link

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 concating on normal js array

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link

@safareli safareli Apr 4, 2017

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){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it ✨

@Avaq
Copy link
Member Author

Avaq commented Apr 13, 2017

Now that this is feature-complete, I'm merging it into master, and changed the default branch to 5.x. Other work on the rewrite will be merged to master via individual pull requests, so reviewers can have an easier time.

@Avaq Avaq merged commit 1a13efd into master Apr 13, 2017
@Avaq Avaq deleted the avaq/es6-rework branch April 13, 2017 14:01
Avaq added a commit that referenced this pull request May 13, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants