Skip to content

Instantly share code, notes, and snippets.

View clinuxrulz's full-sized avatar

Clinton Selke clinuxrulz

View GitHub Profile
class MergeState<A> {
constructor() {}
left : A = null;
left_present : boolean = false;
right : A = null;
right_present : boolean = false;
}
export class Stream<A> {
.
@clinuxrulz
clinuxrulz / cell_apply_no_coalesce.ts
Created June 14, 2019 07:24
Coalesce free Cell::apply
export class Cell<A> {
.
.
.
/**
* Apply a value inside a cell to a function inside a cell. This is the
* primitive for all function lifting.
*/
static apply<A,B>(cf : Cell<(a : A) => B>, ca : Cell<A>, sources? : Source[]) : Cell<B> {
return Transaction.run(() => {
@clinuxrulz
clinuxrulz / overworked_lift.ts
Created June 13, 2019 11:25
overworked sodium cell lift
test("cell lift work", done => {
let lines = [
"Work it harder",
"Make it better",
"Do it faster",
"Makes us stronger"
];
let idx = 0;
let c1 = new CellSink(0);
let c2 = new CellSink(0);
@clinuxrulz
clinuxrulz / EcsTHREESceneUpdater.ts
Created April 9, 2019 21:07
ECS + Sodium + THREE.js
import * as sodium from 'sodiumjs';
import * as THREE from 'three';
import { EcsComponentType } from './EcsComponentType';
import { EcsReadOnlySceneContext } from './EcsReadOnlySceneContext';
import { EcsSceneChanges } from './EcsSceneChanges';
import { IsEcsComponentValue } from './IsEcsComponentValue';
import { ArcComponent } from './components/ArcComponent';
import { Axes2DComponent } from './components/Axes2DComponent';
import { CircleComponent } from './components/CircleComponent';
import { Line3DComponent } from './components/Line3DComponent';
@clinuxrulz
clinuxrulz / cell_trace.ts
Last active February 20, 2019 02:51
Tracking high order dependencies
export function cellTrace<A>(ca: sodium.Cell<A>, extractor: (a: A) => (sodium.Stream<any>|sodium.Cell<any>)[]): sodium.Cell<A> {
let cKeepAlive = sodium.Cell.switchC(ca.map(
a =>
cellLiftArray(
extractor(a).map(
x => {
if (x instanceof sodium.Stream) {
return x.hold({} as any);
} else {
import * as sodium from 'sodiumjs';
import { Option } from './Option';
import * as SodiumUtil from './SodiumUtil';
import { T2 } from './Tuples';
import * as THREE from 'three';
import { Axes3D } from './math/Axes3D';
import { Vector2D } from './math/Vector2D';
import { Vector3D } from './math/Vector3D';
import { Quaternion } from './math/Quaternion';
@clinuxrulz
clinuxrulz / wake-up-sleep.ts
Created February 13, 2019 05:30
wake-up / sleep listeners
class Test<A> {
private _value: A;
private _listeners: ((a:A)=>void)[] = [];
private _onWakeUp: () => {};
private _onSleep: () => {};
public constructor(value: A) {
this._value = value;
}
public static nz.sodium.Cell<Axes3D> watchEntityAxes(
nz.sodium.Cell<Option<EcsReadOnlySceneContext>> cSceneCtxOp,
nz.sodium.Stream<EcsSceneChanges> sSceneChanges,
int entityId
) {
return nz.sodium.Cell.switchC(watchEntityComponentOp(cSceneCtxOp, sSceneChanges, entityId, Axes3DComponent.ecsComponent).lift(
watchEntityComponentOp(cSceneCtxOp, sSceneChanges, entityId, ChildComponent.ecsComponent),
(Option<Axes3DComponent> axesOp, Option<ChildComponent> parentOp) -> {
Option<Integer> parentIdOp = parentOp.map(ChildComponent::parentId);
Axes3D localAxes = axesOp.map(Axes3DComponent::axes3D).orSome(Axes3D.identity);
public static <A> nz.sodium.Cell<Option<A>> watchEntityComponentOp(
nz.sodium.Cell<Option<EcsReadOnlySceneContext>> cSceneCtxOp,
nz.sodium.Stream<EcsSceneChanges> sSceneChanges,
int entityId,
EcsComponent<A> ecsComponent
) {
nz.sodium.StreamLoop<Option<A>> slEntityComponentOp = new sodium.StreamLoop<>();
nz.sodium.Cell<Option<A>> cEntityComponentOp =
slEntityComponentOp
.hold(
@clinuxrulz
clinuxrulz / Delta.java
Last active July 11, 2018 12:12
Incremental Function in Java
package fp.ilc;
import fj.F2;
public class Delta<A,DA> {
private final F2<A,DA,A> _patch;
private final DA _change;
private Delta(F2<A,DA,A> patch, DA change) {
this._patch = patch;