danprince / aeterna Goto Github PK
View Code? Open in Web Editor NEWRewritten as Zaphod
Home Page: https://github.com/danprince/zaphod
Rewritten as Zaphod
Home Page: https://github.com/danprince/zaphod
Would be good to provide an interface for lazy application.
Cheap solution. Wrap eager types in lazy objects that store method calls. Whitelist the methods that resolve with a fixed value.
The value for this
should be autobound onto each method to allow for proper functional usage of the instance methods.
import { Vector } from 'aeterna';
const v = Vector([1, 2, 3]);
v.map(v.peek);
// [3, 3, 3]
Can autobind at declare time:
function Vector() {
const v = [];
Object.keys(Vector.prototype).forEach(function(k) {
Object.defineProperty(v, k, {
enumerable: false,
value: Vector.prototype[k].bind(v)
});
});
}
Or retain access through closures.
function Vector() {
const v = [];
Object.defineProperty(v, 'map', {
enumerable: false,
value: function map(f) {
// refer to `v` instead of `this`
}
});
}
Leaving a list of features that I deliberately dropped for historical context.
Most pipelines can be achieved by chaining calls together. In the cases where they can't comp
and partial
can be used to build pipelines without much syntactic overhead.
If a need arose to transform these collections into Sets and native Maps, then these might be helpful, but otherwise for now, they'd be overkill.
Vectors already have precomputed length property.
Can't yet think of a justification for needing to turn vectors into plain arrays.
Got internals/_toConsumableArray
but not super happy with it. Maybe a primSeq
ish thing will re-appear in the future.
Bit too specific to include.
Doesn't make much sense within the context of the current semantics, might revisit it in the future. Might be more sensible to skip to Just/Nothing though.
Already using native Javascript data structures.
The consumableArray code from the internals namespace is small/simple enough that it makes more sense to move it out into util.
Each data structure needs to come with a predicate for identifying those types.
import { Map } from 'aeterna';
const m = Map({ a: 1, b: 2 });
Map.isMap(m);
Could tag each instance/prototype with a non-enumerable unique string?
Object.defineProperty(Map.prototype, 'type', {
enumerable: false,
value: '#MAP#'
});
Could build this into the prototype chain and use instanceof
?
Would be good to provide a batched interface, so that large transformations can take place over the course of multiple repaints.
For instace, a batched map function.
const { partition, Vector } from 'aeterna';
function batchedMap(f, coll, done) {
const batches = partition(coll, 500);
let mapped = Vector([]);
function $recur(batches) {
if(batches.length == 0) done(mapped);
const batch = batches.first();
mapped = mapped.concat(batch.map(f));
requestAnimationFrame(() => $recur(batches.rest()));
}
$recur(batches);
}
Can't think of a good way to create this as a generic wrapper unless each operation was to expose some kind of request/response interface, but that would force asynchronicity on all operations.
It would be really handy for some methods to be shared between vectors and maps. Specifically get/getIn
and assoc/assocIn/updateIn
.
There should be no reason why these functions can't be moved out to a common namespace, then required by both types.
// vector.js
Vector.prototype = {
assocIn: require('../common/assoc-in');
};
// map.js
Map.prototype = {
assocIn: require('../common/assoc-in');
};
The other option is to go one step further and have a seq-like prototype that both inherit from.
Seq = {
assocIn: require('./assocIn')
};
Map.prototype = Object.create(Seq);
Vector.prototype = Object.create(Seq);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.