Skip to content

Commit

Permalink
docs(intervals): fix readme code example
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 24, 2020
1 parent 5813afc commit acfa908
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
28 changes: 17 additions & 11 deletions packages/intervals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ Package sizes (gzipped): ESM: 1.4KB / CJS: 1.5KB / UMD: 1.5KB

## Dependencies

- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/master/packages/api)
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/master/packages/checks)
- [@thi.ng/dlogic](https://github.com/thi-ng/umbrella/tree/master/packages/dlogic)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/master/packages/errors)
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
- [@thi.ng/dlogic](https://github.com/thi-ng/umbrella/tree/develop/packages/dlogic)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)

## API

[Generated API docs](https://docs.thi.ng/umbrella/intervals/)

```ts
import { Interval } from "@thi.ng/intervals";
import { interval, Interval } from "@thi.ng/intervals";

// [0 .. +∞] (fully closed)
a = Interval.withMin(0);
Expand All @@ -68,7 +68,7 @@ i.toString();
// [0 .. 1)

// parse from string
Interval.parse("[0 .. 1)")
interval("[0 .. 1)")
// Interval { l: 0, r: 1, lopen: false, ropen: true }

i.contains(1);
Expand All @@ -77,14 +77,20 @@ i.contains(1);
i.contains(0.999999);
// true

// classify point (true if x < LHS)
// classify interval relative to point (true if RHS < x)
i.isBefore(-1)
// false

i.isBefore(1)
// true

// classify point (true if x > RHS)
i.isAfter(1);
// classify interval relative to point (true if LHS > x)
i.isAfter(-1);
// true

i.isAfter(1);
// false

// grow interval to include 2 => [0 ... 2]
i2 = i.include(2);

Expand All @@ -94,11 +100,11 @@ i.compare(i2);

// classify WRT given interval arg
i.classify(Interval.infinity());
// Classifier.SUBSET
// 3 (aka Classifier.SUBSET)

// create transformed interval
// (here scaled around centroid)
i.map((x) => x + (x - i.centroid()) * 2);
i.map((x) => x + (x - i.centroid()) * 2).toString();
// [-1 .. 2)

// iterator of decimated interval values
Expand Down
20 changes: 13 additions & 7 deletions packages/intervals/README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ${examples}
${docLink}

```ts
import { Interval } from "@thi.ng/intervals";
import { interval, Interval } from "@thi.ng/intervals";

// [0 .. +∞] (fully closed)
a = Interval.withMin(0);
Expand All @@ -61,7 +61,7 @@ i.toString();
// [0 .. 1)

// parse from string
Interval.parse("[0 .. 1)")
interval("[0 .. 1)")
// Interval { l: 0, r: 1, lopen: false, ropen: true }

i.contains(1);
Expand All @@ -70,14 +70,20 @@ i.contains(1);
i.contains(0.999999);
// true

// classify point (true if x < LHS)
// classify interval relative to point (true if RHS < x)
i.isBefore(-1)
// false

i.isBefore(1)
// true

// classify point (true if x > RHS)
i.isAfter(1);
// classify interval relative to point (true if LHS > x)
i.isAfter(-1);
// true

i.isAfter(1);
// false

// grow interval to include 2 => [0 ... 2]
i2 = i.include(2);

Expand All @@ -87,11 +93,11 @@ i.compare(i2);

// classify WRT given interval arg
i.classify(Interval.infinity());
// Classifier.SUBSET
// 3 (aka Classifier.SUBSET)

// create transformed interval
// (here scaled around centroid)
i.map((x) => x + (x - i.centroid()) * 2);
i.map((x) => x + (x - i.centroid()) * 2).toString();
// [-1 .. 2)

// iterator of decimated interval values
Expand Down

0 comments on commit acfa908

Please sign in to comment.