Skip to content

Commit

Permalink
Rename flatten function and methods to flat
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Sep 6, 2019
1 parent ccd88fc commit c4b0282
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ this. The table below gives an overview.
| Outer | Inner | Function |
| -------- | -------- | -------------------------- |
| Behavior | anything | `sample` (when inside Now) |
| Behavior | Behavior | `flatten` |
| Behavior | Behavior | `flat` |
| Behavior | Stream | `shiftCurrent` |
| Stream | Behavior | `switcher`, `selfie` |
| Stream | Stream | `shift` |
Expand Down
2 changes: 1 addition & 1 deletion src/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export abstract class Behavior<A> extends Reactive<A, BListener>
chain<B>(fn: (a: A) => Behavior<B>): Behavior<B> {
return new FlatMapBehavior(this, fn);
}
flatten<B>(this: Behavior<Behavior<B>>): Behavior<B> {
flat<B>(this: Behavior<Behavior<B>>): Behavior<B> {
return new FlatMapBehavior(this, (a) => a);
}
at(t?: number): A {
Expand Down
2 changes: 1 addition & 1 deletion src/future.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export abstract class Future<A> extends Reactive<A, SListener<A>>
chain<B>(f: (a: A) => Future<B>): Future<B> {
return new FlatMapFuture(f, this);
}
flatten<B>(this: Future<Future<B>>): Future<B> {
flat<B>(this: Future<Future<B>>): Future<B> {
return new FlatMapFuture((f) => f, this);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export function lift<R>(f: (...args: any) => R, ...args: any): any {
return args[0].lift(f, ...args);
}

export function flatten<A>(b: Behavior<Behavior<A>>): Behavior<A>;
export function flatten<A>(f: Future<Future<A>>): Future<A>;
export function flatten<A>(n: Now<Now<A>>): Now<A>;
export function flatten(o: { flatten: () => any }): any {
return o.flatten();
export function flat<A>(b: Behavior<Behavior<A>>): Behavior<A>;
export function flat<A>(f: Future<Future<A>>): Future<A>;
export function flat<A>(n: Now<Now<A>>): Now<A>;
export function flat(o: { flat: () => any }): any {
return o.flat();
}

export function push<A>(a: A, sink: SinkBehavior<A> | SinkStream<A>): void {
Expand Down
2 changes: 1 addition & 1 deletion src/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export abstract class Now<A> {
chain<B>(f: (a: A) => Now<B>): Now<B> {
return new FlatMapNow(this, f);
}
flatten<B>(this: Now<Now<B>>): Now<B> {
flat<B>(this: Now<Now<B>>): Now<B> {
return new FlatMapNow(this, (n) => n);
}
ap<B>(a: Now<(a: A) => B>): Now<B> {
Expand Down
2 changes: 1 addition & 1 deletion test/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("animation", () => {
duration: 100
};

const t = transitionBehavior(config, 0, target, time).flatten();
const t = transitionBehavior(config, 0, target, time).flat();
t.subscribe(() => "");
assert.strictEqual(at(t), 0);
time.push(10);
Expand Down
6 changes: 3 additions & 3 deletions test/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ describe("behavior", () => {
assert.deepEqual(cb.args, [[2], [14]]);
});
});
describe("flatten", () => {
describe("flat", () => {
it("has proper type", () => {
const b = Behavior.of(Behavior.of("foo"));
H.flatten(b).map((s) => s + "bar");
H.flat(b).map((s) => s + "bar");
});
});
describe("integrateFrom", () => {
Expand Down Expand Up @@ -972,7 +972,7 @@ describe("Behavior and Stream", () => {
let variable = -1;
const pullingB = H.fromFunction(() => variable);
const outer = sinkBehavior<Behavior<number>>(pushingB);
const flattened = H.flatten(outer);
const flattened = H.flat(outer);
const pushSpy = spy();
let pull: () => void;
const handlePulling = (p) => {
Expand Down
4 changes: 2 additions & 2 deletions test/future.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ describe("Future", () => {
assert.deepEqual(result, [1, 2]);
});
});
describe("flatten", () => {
describe("flat", () => {
it("resolves when inner occurs last", () => {
const outer = sinkFuture<Future<number>>();
const inner = sinkFuture<number>();
const flattened = H.flatten(outer);
const flattened = H.flat(outer);
const cb = spy();
flattened.subscribe(cb);
outer.resolve(inner);
Expand Down
2 changes: 1 addition & 1 deletion test/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("Now", () => {
assert.strictEqual(ref2.ref, "World");
});
it("can flatten pure nows", () => {
assert.strictEqual(runNow(Now.of(Now.of(12)).flatten()), 12);
assert.strictEqual(runNow(Now.of(Now.of(12)).flat()), 12);
});
it("throws in go if incorrect monad is yielded", (done) => {
const now = go(
Expand Down

0 comments on commit c4b0282

Please sign in to comment.