Skip to content

Instantly share code, notes, and snippets.

Clinton Selke clinuxrulz

Block or report user

Report or block clinuxrulz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cell_arrayed_keyed.ts
export function cellArrayKeyed2<K,A,B>(keyEq: (a:K,b:K)=>boolean, keyExtractor: (a:A)=>K, transform: (a:A) => B, cas: sodium.Cell<A[]>): sodium.Cell<B[]> {
return sodium.Operational
.updates(cas)
.accumLazy(
cas.sampleLazy().map(as => as.map(a => T2.of(keyExtractor(a), transform(a)))),
(nextAs: A[], lastResult: T2<K,B>[]) => {
let nextResult: T2<K,B>[] = [];
for (let i = 0; i < nextAs.length; ++i) {
let a = nextAs[i];
let key = keyExtractor(a);
@clinuxrulz
clinuxrulz / cell_switchC_no_coalesce.ts
Last active Jun 16, 2019
Coalesce free Cell::switchC
View cell_switchC_no_coalesce.ts
export class Cell<A> {
.
.
.
static switchC<A>(cca : Cell<Cell<A>>) : Cell<A> {
return Transaction.run(() => {
const za = cca.sampleLazy().map((ba : Cell<A>) => ba.sample()),
out = new StreamWithSend<A>();
let outValue: A = null;
View stream_merge_no_coalesce.ts
class MergeState<A> {
constructor() {}
left : A = null;
left_present : boolean = false;
right : A = null;
right_present : boolean = false;
}
export class Stream<A> {
.
View cell_apply_no_coalesce.ts
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 Jun 13, 2019
overworked sodium cell lift
View overworked_lift.ts
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);
View EcsTHREESceneUpdater.ts
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 Feb 20, 2019
Tracking high order dependencies
View cell_trace.ts
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 {
View compose_three.js.ts
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 Feb 13, 2019
wake-up / sleep listeners
View wake-up-sleep.ts
class Test<A> {
private _value: A;
private _listeners: ((a:A)=>void)[] = [];
private _onWakeUp: () => {};
private _onSleep: () => {};
public constructor(value: A) {
this._value = value;
}
View EgUseWatchEntityComponent.java
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);
You can’t perform that action at this time.