From da01f43e1d02b27817f663f0396d3dd02e1593f4 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 17 Dec 2017 18:38:28 -0200 Subject: [PATCH 01/25] Updates changelog for 2.0.1 --- packages/base/CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/base/CHANGELOG.md b/packages/base/CHANGELOG.md index fa85942..8cf480c 100644 --- a/packages/base/CHANGELOG.md +++ b/packages/base/CHANGELOG.md @@ -15,6 +15,27 @@ Each version entry is written as a heading in the format `[] - Y --- + +## [2.0.1] - 2017-07-22 + +### Documentation + + - Many typos were fixed ([PR #151](https://github.com/origamitower/folktale/pull/151) by @gvillalta99; [PR #165](https://github.com/origamitower/folktale/pull/165) by @MichaelQQ, [PR #145](https://github.com/origamitower/folktale/pull/145) by @stabbylambda, [PR #143](https://github.com/origamitower/folktale/pull/143) and [PR #144](https://github.com/origamitower/folktale/pull/144) by @floriansimon1) + - Migration documentation on Task has been improved, and examples fixed ([PR #160](https://github.com/origamitower/folktale/pull/160)) + - Added notes on shims for older platforms ([PR #161](https://github.com/origamitower/folktale/pull/161)) + - Fixed some Validation examples ([PR #154](https://github.com/origamitower/folktale/pull/154) by @scotttrinh) + + +### DEPRECATED FEATURES + + - Renamed `Future.recover` to `Future.orElse`. `Future.recover` was deprecated. ([PR #146](https://github.com/origamitower/folktale/pull/146)) + + +### Miscellaneous + + - We've moved from Make to Furipota, so the build system is cross-platform now ([PR #148](https://github.com/origamitower/folktale/pull/148)) + + ## [2.0.0] - 2017-07-15 ### New features From 275ec9eb9c225942f818f8f9cb2618047ae1cf54 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 24 Sep 2017 21:55:37 -0300 Subject: [PATCH 02/25] Initial work on TypeScript typings This adds partial support for Core, Validation, Result, and Maybe --- packages/base/index.d.ts | 195 +++++++++++++++++++++++++++++++++++++ packages/base/package.json | 3 +- 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 packages/base/index.d.ts diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts new file mode 100644 index 0000000..1e40ba6 --- /dev/null +++ b/packages/base/index.d.ts @@ -0,0 +1,195 @@ +declare namespace folktale { + // -- Core + interface Lambda { + compose(f: (_: B) => C, g: (_: A) => B): (_: A) => C; + constant(value: A): (_: B) => A; + identity(value: A): A; + } + + interface Object { + fromPairs(pairs: [string, A][]): { [key: string]: A}; + toPairs(object: {[key: string]: A}): [string, A][]; + values(object: {[key: string]: A}): A[]; + mapValues(object: {[key: string]: A}, fn: (_: A) => B): {[key: string]: B}; + } + + interface Core { + lambda: Lambda; + object: Object; + } + + // -- Maybe + type Semigroup = A & { + concat(this: Semigroup, that: Semigroup): Semigroup + } + + type Maybe = Just | Nothing + + interface Just { + __type: A; + __tag: 'Just'; + value: A; + map(f: (_: A) => B): Maybe; + apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; + chain(f: (_: A) => Maybe): Maybe; + getOrElse(_default: A): A; + orElse(f: (_: A) => Maybe): Maybe; + concat>(this: Maybe, x: Maybe): Maybe; + filter(f: (_: A) => boolean): Maybe; + matchWith(patterns: { + Just(_: { value: A }): R + Nothing(_: {}): R + }): R; + toResult(fallback: B): Result; + toValidation(fallback: B): Validation; + } + + interface Nothing { + __type: A; + __tag: 'Nothing'; + map(f: (_: A) => B): Maybe; + apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; + chain(f: (_: A) => Maybe): Maybe; + getOrElse(_default: A): A; + orElse(f: () => Maybe): Maybe; + concat>(this: Maybe, x: Maybe): Maybe; + filter(f: (_: A) => boolean): Maybe; + matchWith(patterns: { + Just(_: { value: A }): R + Nothing(_: {}): R + }): R; + toResult(fallback: B): Result; + toValidation(fallback: B): Validation; + } + + interface StaticMaybe { + of(value: A): Maybe; + empty(): Maybe; + Just(value: A): Maybe; + Nothing(): Maybe; + hasInstance(value: any): boolean; + fromNullable(_: A | null): Maybe; + fromResult(_: Result): Maybe; + fromValidation(_: Validation): Maybe; + } + + + // -- Result + type Result = Error | Ok; + + interface Error { + __type0: A; + __type1: B; + __tag: 'Error'; + value: A; + + map(f: (_: B) => C): Result; + apply(this: Result C>, that: Result): Result; + chain(f: (_: B) => Result): Result; + getOrElse(_default: B): B; + orElse(f: (_: A) => A): Result; + concat>(this: Result, that: Result): Result; + swap(): Result; + bimap(error: (_: A) => C, ok: (_: B) => D): Result; + mapError(f: (_: A) => C): Result; + filter(f: (_: B) => boolean): Result; + merge(): A | B; + toValidation(): Validation; + toMaybe(): Maybe; + } + + interface Ok { + __type0: A; + __type1: B; + __tag: 'Ok'; + value: B; + + map(f: (_: B) => C): Result; + apply(this: Result C>, that: Result): Result; + chain(f: (_: B) => Result): Result; + getOrElse(_default: B): B; + orElse(f: (_: A) => A): Result; + concat>(this: Result, that: Result): Result; + swap(): Result; + bimap(error: (_: A) => C, ok: (_: B) => D): Result; + mapError(f: (_: A) => C): Result; + filter(f: (_: B) => boolean): Result; + merge(): A | B; + toValidation(): Validation; + toMaybe(): Maybe; + } + + interface StaticResult { + Error(value: A): Result; + Ok(value: B): Result; + hasInstance(value: any): boolean; + of(value: B): Result; + try(f: (() => B)): Result; + fromNullable(value: B | null): Result; + fromValidation(value: Validation): Result; + fromMaybe(value: Maybe, failure: A): Result; + } + + + // -- Validation + type Validation = Failure | Success; + + interface Failure { + __type0: A; + __type1: B; + __tag: 'Failure'; + value: A; + + map(f: (_: B) => C): Validation; + apply(this: Validation C>, that: Validation): Validation; + getOrElse(_default: B): B; + orElse(f: (_: A) => A): Validation; + concat>(this: Validation, that: Validation): Validation; + swap(): Validation; + bimap(error: (_: A) => C, ok: (_: B) => D): Validation; + mapFailure(f: (_: A) => C): Validation; + filter(f: (_: B) => boolean): Validation; + merge(): A | B; + toResult(): Result; + toMaybe(): Maybe; + } + + interface Success { + __type0: A; + __type1: B; + __tag: 'Success'; + value: B; + + map(f: (_: B) => C): Validation; + apply(this: Validation C>, that: Validation): Validation; + getOrElse(_default: B): B; + orElse(f: (_: A) => A): Validation; + concat>(this: Validation, that: Validation): Validation; + swap(): Validation; + bimap(error: (_: A) => C, ok: (_: B) => D): Validation; + mapFailure(f: (_: A) => C): Validation; + filter(f: (_: B) => boolean): Validation; + merge(): A | B; + toResult(): Result; + toMaybe(): Maybe; + } + + interface StaticValidation { + Failure(value: A): Validation; + Success(value: B): Validation; + hasInstance(value: any): boolean; + of(value: B): Validation; + collect>(validations: Validation[]): Validation; + fromNullable(value: B | null): Validation; + fromResult(value: Result): Validation; + fromMaybe(value: Maybe, failure: A): Validation; + } + + // -- Entry point + export const core: Core; + export const maybe: StaticMaybe; + export const result: StaticResult; + export const validation: StaticValidation; +} + +export = folktale \ No newline at end of file diff --git a/packages/base/package.json b/packages/base/package.json index deaf49a..52c05a1 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,8 +1,9 @@ { "name": "folktale", - "version": "2.0.1", + "version": "2.1.0", "description": "A suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs and more reuse.", "main": "./index.js", + "typings": "./index.d.ts", "repository": { "type": "git", "url": "https://github.com/origamitower/folktale" From c4c759f5fcc17485ccd4127a09eb059279c63151 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 7 Oct 2017 23:17:02 -0300 Subject: [PATCH 03/25] Partial types for concurrency modules --- packages/base/index.d.ts | 112 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 1e40ba6..37c6a24 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -75,9 +75,9 @@ declare namespace folktale { // -- Result - type Result = Error | Ok; + type Result = Err | Ok; - interface Error { + interface Err { __type0: A; __type1: B; __tag: 'Error'; @@ -185,11 +185,119 @@ declare namespace folktale { fromMaybe(value: Maybe, failure: A): Validation; } + // -- Concurrency + interface Future { + toPromise(): Promise + inspect(): string + toString(): string + + willMatchWith(patterns: { + Cancelled(): Future, + Resolved(value: B): Future, + Rejected(reason: A): Future + }): Future + + listen(patterns: { + onCancelled(): void, + onResolved(value: B): void, + onRejected(reason: A): void + }): Future + + orElse(handler: (_: A) => Future): Future + swap(): Future + apply(this: Future C>, that: Future): Future + bimap(onRejected: (_: A) => C, onResolved: (_: B) => D): Future + chain(f: (_: B) => Future): Future + map(f: (_: B) => C): Future + mapRejected(f: (_: A) => C): Future + + + /** @deprecated */ + recover(handler: (_: A) => Future): Future + } + + interface StaticFuture { + of(value: B): Future + rejected(reason: A): Future + fromPromise(promise: Promise): Future + } + + interface TaskExecution { + cacel(): TaskExecution + + listen(pattern: { + onCancelled(): void, + onResolved(value: B): void, + onRejected(reason: A): void + }): TaskExecution + + promise(): Promise + future(): Future + } + + interface Task { + and(that: Task): Task + or(that: Task): Task + run(): TaskExecution + + willMatchWith(patterns: { + Cancelled(): Task, + Resolved(value: B): Task, + Rejected(reason: A): Task + }): Task + + orElse(handler: (_: A) => Task): Task + swap(): Task + apply(this: Task B2>, that: Task): Task + bimap(onRejected: (_: A) => A2, onResolved: (_: B) => B2): Task + chain(f: (_: B) => Task): Task + map(f: (_: B) => B2): Task + mapRejected(f: (_: A) => A2): Task + } + + interface StaticTask { + waitAll(tasks: Task[]): Task + waitAny(tasks: Task[]): Task + of(value: V): Task + rejected(reason: E): Task + task(resolver: TaskResolver): Task + fromNodeback(fn: (cb: (e: E, v: V) => void) => void): () => Task + fromNodeback(fn: (a1: A, cb: (e: E, v: V) => void) => void): (a1: A) => Task + fromNodeback(fn: (a1: A, a2: A2, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2) => Task + fromNodeback(fn: (a1: A, a2: A2, a3: A3, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3) => Task + fromNodeback(fn: (cb: (a1: A, a2: A2, a3: A3, a4: A4, e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4) => Task + fromNodeback(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Task + fromNodeback(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Task + + fromPromised(fn: () => Promise): () => Task + fromPromised(fn: (a1: A) => Promise): (a1: A) => Task + fromPromised(fn: (a1: A, a2: A2) => Promise): (a1: A, a2: A2) => Task + fromPromised(fn: (a1: A, a2: A2, a3: A3) => Promise): (a1: A, a2: A2, a3: A3) => Task + fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4) => Promise): (a1: A, a2: A2, a3: A3, a4: A4) => Task + fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Promise): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Task + fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Promise): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Task + + do(generator: GeneratorFunction): Task + } + + interface TaskResolver { + resolve(value: V): void + reject(reason: E): void + cancel(): void + cleanup(handler: () => void): void + onCancelled(handler: () => void): void + isCancelled: boolean + } + // -- Entry point export const core: Core; export const maybe: StaticMaybe; export const result: StaticResult; export const validation: StaticValidation; + export const concurrency: { + task: StaticTask + future: StaticFuture + }; } export = folktale \ No newline at end of file From eb4521440abb65193cc8dc79ec41b2a2b94aef5d Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 7 Oct 2017 23:34:36 -0300 Subject: [PATCH 04/25] Tiny helper for releases for now --- build.frp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build.frp b/build.frp index e4b51b9..f005cde 100644 --- a/build.frp +++ b/build.frp @@ -205,3 +205,19 @@ export define documentation = export define lint = # Notifies about formatting problems and potential bugs in the source code. run-lint (root / ".eslintrc.json") + + +export define release = + # Releases `base` + let release = root / "base" / "releases" / "new" in + let pkg = root / "base" in + let show-copy = show-file-operation "COPY" in + do action test + action lint + action bundle-source + action make-directory release | Debug.trace @ -prefix: "MKDIR" + action copy (pkg / "build") @ -to: release -overwrite: true |> show-copy + action copy (pkg / "CHANGELOG.md") @ -to: (release / "CHANGELOG.md") -overwrite: true |> show-copy + action copy (pkg / "package.json") @ -to: (release / "package.json") -overwrite: true |> show-copy + action copy (pkg / "CONTRIBUTORS") @ -to: (release / "CONTRIBUTORS") -overwrite: true |> show-copy + action copy (pkg / "index.d.ts") @ -to: (release / "index.d.ts") -overwrite: true |> show-copy \ No newline at end of file From d6daff6185cdfc286a9b8c8c71af60c770e595f5 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 7 Oct 2017 23:48:23 -0300 Subject: [PATCH 05/25] (fix) incorrect package path --- build.frp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.frp b/build.frp index f005cde..c5f55ba 100644 --- a/build.frp +++ b/build.frp @@ -209,8 +209,8 @@ export define lint = export define release = # Releases `base` - let release = root / "base" / "releases" / "new" in - let pkg = root / "base" in + let release = root / "packages" / "base" / "releases" / "new" in + let pkg = root / "packages" / "base" in let show-copy = show-file-operation "COPY" in do action test action lint From 86d353f8e672418e221aa5d3600cb9224b8a5254 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:05:45 -0200 Subject: [PATCH 06/25] Overloads for waitAll --- packages/base/index.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 37c6a24..94e0f4c 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -256,11 +256,20 @@ declare namespace folktale { } interface StaticTask { + waitAll(tasks: [Task, Task]): Task + waitAll(tasks: [Task, Task, Task]): Task + waitAll(tasks: [Task, Task, Task, Task]): Task + waitAll(tasks: [Task, Task, Task, Task, Task]): Task + waitAll(tasks: [Task, Task, Task, Task, Task, Task]): Task waitAll(tasks: Task[]): Task + waitAny(tasks: Task[]): Task + + of(value: V): Task rejected(reason: E): Task task(resolver: TaskResolver): Task + fromNodeback(fn: (cb: (e: E, v: V) => void) => void): () => Task fromNodeback(fn: (a1: A, cb: (e: E, v: V) => void) => void): (a1: A) => Task fromNodeback(fn: (a1: A, a2: A2, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2) => Task From 22e3b644b7640adbdc1150db9ee9df22a86053ac Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:12:34 -0200 Subject: [PATCH 07/25] Type for mapEntries --- packages/base/index.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 94e0f4c..cb10cff 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -11,6 +11,16 @@ declare namespace folktale { toPairs(object: {[key: string]: A}): [string, A][]; values(object: {[key: string]: A}): A[]; mapValues(object: {[key: string]: A}, fn: (_: A) => B): {[key: string]: B}; + mapEntries: MapEntries + } + + type Dict = { [key: string]: A }; + + interface MapEntries { + (object: Dict, transform: (pair: [string, A]) => [string, B], define: (object: Dict, key: string, value: B) => Dict): Dict + + overwrite(object: Dict, transform: (pair: [string, A]) => [string, B]): Dict + unique(object: Dict, transform: (pair: [string, A]) => [string, B]): Dict } interface Core { From b396004b607d62e17ddfc1db52b8538a51c91078 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:18:19 -0200 Subject: [PATCH 08/25] Fixes typo --- packages/base/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index cb10cff..df71eda 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -233,7 +233,7 @@ declare namespace folktale { } interface TaskExecution { - cacel(): TaskExecution + cancel(): TaskExecution listen(pattern: { onCancelled(): void, From 6828127a937cf40acf0087e3c785d60bb3700c43 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:19:37 -0200 Subject: [PATCH 09/25] Ignores VSCode settings --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0479f5b..b98e253 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ npm-debug.log /test/build/ /tools/static-docs/lib/ /tools/static-docs/resources/html/*.css -.nyc_output/ \ No newline at end of file +.nyc_output/ +.vscode/settings.json \ No newline at end of file From e07d54924ff89e46155b5d4421f82ede271f241d Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:34:14 -0200 Subject: [PATCH 10/25] Types for Conversions --- packages/base/index.d.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index df71eda..14414c6 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -308,11 +308,45 @@ declare namespace folktale { isCancelled: boolean } + // -- Conversions + interface Conversions { + futureToPromise(future: Future): Promise + maybeToResult(maybe: Maybe, fallback: B): Result + maybeToValidation(maybe: Maybe, fallback: B): Validation + promiseToFuture(promise: Promise): Future + resultToMaybe(result: Result): Maybe + resultToValidation(result: Result): Validation + validationToMaybe(validation: Validation): Maybe + validationToResult(validation: Validation): Result + + + promisedToTask(fn: () => Promise): () => Task + promisedToTask(fn: (a: A1) => Promise): (a: A1) => Task + promisedToTask(fn: (a: A1, b: A2) => Promise): (a: A1, b: A2) => Task + promisedToTask(fn: (a: A1, b: A2, c: A3) => Promise): (a: A1, b: A2, c: A3) => Task + promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4) => Promise): (a: A1, b: A2, c: A3, d: A4) => Task + promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5) => Promise): (a: A1, b: A2, c: A3, d: A4, e: A5) => Task + promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Promise): (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Task + + nodebackToTask(fn: (cb: (error: E, value: V) => void) => void): () => Task + nodebackToTask(fn: (a: A1, cb: (error: E, value: V) => void) => void): (a: A1) => Task + nodebackToTask(fn: (a: A1, b: A2, cb: (error: E, value: V) => void) => void): (a: A1, b: A2) => Task + nodebackToTask(fn: (a: A1, b: A2, c: A3, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3) => Task + nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4) => Task + nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4, e: A5) => Task + nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Task + + nullableToMaybe(value: A | null | undefined): Maybe + nullableToResult(value: A | null | undefined): Result + nullableToValidation(value: A | null | undefined, fallback: B): Validation + } + // -- Entry point export const core: Core; export const maybe: StaticMaybe; export const result: StaticResult; export const validation: StaticValidation; + export const conversions: Conversions; export const concurrency: { task: StaticTask future: StaticFuture From 2d552ab1e9db86a3009138315c4137c76e40e876 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Mon, 6 Nov 2017 22:40:07 -0200 Subject: [PATCH 11/25] Bumps to alpha3 --- packages/base/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/package.json b/packages/base/package.json index 52c05a1..51a9088 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,6 +1,6 @@ { "name": "folktale", - "version": "2.1.0", + "version": "2.1.0-alpha3", "description": "A suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs and more reuse.", "main": "./index.js", "typings": "./index.d.ts", From 8db240fbdb6641623004c40934f25bc54509f0f5 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Fri, 8 Dec 2017 22:09:24 -0200 Subject: [PATCH 12/25] Fixes apply/orElse types, adds missing methods --- packages/base/index.d.ts | 70 ++++++++++--- packages/base/test.ts | 189 ++++++++++++++++++++++++++++++++++++ packages/base/tsconfig.json | 28 ++++++ 3 files changed, 275 insertions(+), 12 deletions(-) create mode 100644 packages/base/test.ts create mode 100644 packages/base/tsconfig.json diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 14414c6..cc3e28f 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -40,10 +40,10 @@ declare namespace folktale { __tag: 'Just'; value: A; map(f: (_: A) => B): Maybe; - apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; + apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; chain(f: (_: A) => Maybe): Maybe; getOrElse(_default: A): A; - orElse(f: (_: A) => Maybe): Maybe; + orElse(f: () => Maybe): Maybe; concat>(this: Maybe, x: Maybe): Maybe; filter(f: (_: A) => boolean): Maybe; matchWith(patterns: { @@ -52,13 +52,18 @@ declare namespace folktale { }): R; toResult(fallback: B): Result; toValidation(fallback: B): Validation; + inspect(): string; + toString(): string; + equals(that: Maybe): boolean; + unsafeGet(): A; + fold(onJust: (_: A) => B, onNothing: () => B): B; } interface Nothing { __type: A; __tag: 'Nothing'; map(f: (_: A) => B): Maybe; - apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; + apply(this: Maybe<(_: A) => B>, f: Maybe): Maybe; chain(f: (_: A) => Maybe): Maybe; getOrElse(_default: A): A; orElse(f: () => Maybe): Maybe; @@ -70,6 +75,11 @@ declare namespace folktale { }): R; toResult(fallback: B): Result; toValidation(fallback: B): Validation; + inspect(): string; + toString(): string; + equals(that: Maybe): boolean; + unsafeGet(): A; + fold(onJust: (_: A) => B, onNothing: () => B): B; } interface StaticMaybe { @@ -94,10 +104,10 @@ declare namespace folktale { value: A; map(f: (_: B) => C): Result; - apply(this: Result C>, that: Result): Result; + apply(this: Result C>, that: Result): Result; chain(f: (_: B) => Result): Result; getOrElse(_default: B): B; - orElse(f: (_: A) => A): Result; + orElse(f: (_: A) => Result): Result; concat>(this: Result, that: Result): Result; swap(): Result; bimap(error: (_: A) => C, ok: (_: B) => D): Result; @@ -106,6 +116,15 @@ declare namespace folktale { merge(): A | B; toValidation(): Validation; toMaybe(): Maybe; + equals(that: Result): boolean; + inspect(): string; + toString(): string; + unsafeGet(): B; + fold(onError: (_: A) => C, onOk: (_: B) => C): C; + matchWith(pattern: { + Error: (_: { value: A }) => R + Ok: (_: { value: B }) => R + }): R; } interface Ok { @@ -115,10 +134,10 @@ declare namespace folktale { value: B; map(f: (_: B) => C): Result; - apply(this: Result C>, that: Result): Result; + apply(this: Result C>, that: Result): Result; chain(f: (_: B) => Result): Result; getOrElse(_default: B): B; - orElse(f: (_: A) => A): Result; + orElse(f: (_: A) => Result): Result; concat>(this: Result, that: Result): Result; swap(): Result; bimap(error: (_: A) => C, ok: (_: B) => D): Result; @@ -127,6 +146,15 @@ declare namespace folktale { merge(): A | B; toValidation(): Validation; toMaybe(): Maybe; + equals(that: Result): boolean; + inspect(): string; + toString(): string; + unsafeGet(): B; + fold(onError: (_: A) => C, onOk: (_: B) => C): C; + matchWith(pattern: { + Error: (_: { value: A }) => R + Ok: (_: { value: B }) => R + }): R; } interface StaticResult { @@ -135,7 +163,7 @@ declare namespace folktale { hasInstance(value: any): boolean; of(value: B): Result; try(f: (() => B)): Result; - fromNullable(value: B | null): Result; + fromNullable(value: B | null | undefined): Result; fromValidation(value: Validation): Result; fromMaybe(value: Maybe, failure: A): Result; } @@ -151,9 +179,9 @@ declare namespace folktale { value: A; map(f: (_: B) => C): Validation; - apply(this: Validation C>, that: Validation): Validation; + apply>(this: Validation C>, that: Validation): Validation; getOrElse(_default: B): B; - orElse(f: (_: A) => A): Validation; + orElse(f: (_: A) => Validation): Validation; concat>(this: Validation, that: Validation): Validation; swap(): Validation; bimap(error: (_: A) => C, ok: (_: B) => D): Validation; @@ -162,6 +190,15 @@ declare namespace folktale { merge(): A | B; toResult(): Result; toMaybe(): Maybe; + equals(that: Validation): boolean; + inspect(): string; + toString(): string; + unsafeGet(): B; + fold(onFailure: (_: A) => C, onSuccess: (_: B) => C): C; + matchWith(pattern: { + Failure: (_: { value: A }) => R + Success: (_: { value: B }) => R + }): R; } interface Success { @@ -171,9 +208,9 @@ declare namespace folktale { value: B; map(f: (_: B) => C): Validation; - apply(this: Validation C>, that: Validation): Validation; + apply>(this: Validation C>, that: Validation): Validation; getOrElse(_default: B): B; - orElse(f: (_: A) => A): Validation; + orElse(f: (_: A) => Validation): Validation; concat>(this: Validation, that: Validation): Validation; swap(): Validation; bimap(error: (_: A) => C, ok: (_: B) => D): Validation; @@ -182,6 +219,15 @@ declare namespace folktale { merge(): A | B; toResult(): Result; toMaybe(): Maybe; + equals(that: Validation): boolean; + inspect(): string; + toString(): string; + unsafeGet(): B; + fold(onFailure: (_: A) => C, onSuccess: (_: B) => C): C; + matchWith(pattern: { + Failure: (_: { value: A }) => R + Success: (_: { value: B }) => R + }): R; } interface StaticValidation { diff --git a/packages/base/test.ts b/packages/base/test.ts new file mode 100644 index 0000000..36cc042 --- /dev/null +++ b/packages/base/test.ts @@ -0,0 +1,189 @@ +import * as _ from './index'; +import { Maybe, Validation, Result } from './index'; + +//#region Core.Lambda +{ + const { compose, constant, identity } = _.core.lambda; + + const f = (a: number) => a.toString(); + const g = (a: string) => a.toUpperCase(); + + const ex1: (_: number) => string = compose(g, f); + const ex2: string = constant("foo")(1); + const ex3: number = identity(1); +} +//#endregion + + +//#region Core.Object +{ + const { fromPairs, toPairs, values, mapValues, mapEntries } = _.core.object; + const xs: [string, number][] = [['a', 1], ['b', 2]]; + + const ex1: { [key: string]: number } = fromPairs(xs); + const ex2: [string, number][] = toPairs({ a: 1, b: 2 }); + const ex3: number[] = values({ a: 1, b: 2 }); + const ex4: { [key: string]: string } = mapValues({ a: 1, b: 2 }, (x) => x.toString()); + const ex5: { [key: string]: string } = mapEntries.overwrite({ a: 1 }, ([k, v]) => [k, v.toString()]); + const ex6: { [key: string]: string } = mapEntries.unique({ a: 1 }, ([k, v]) => [k, v.toString()]); + const ex7: { [key: string]: string } = mapEntries({ a: 1 }, + ([k, v]) => [k, v.toString()], + (o, k, v) => Object.assign(o, { [k]: v })); +} +//#endregion + + +//#region Maybe +{ + const ex1: Maybe = _.maybe.of("foo"); + const ex2: Maybe = _.maybe.empty(); + const ex3: Maybe = _.maybe.Just("foo"); + const ex4: Maybe = _.maybe.Nothing(); + + const ex5: boolean = _.maybe.hasInstance(null); + const ex6: Maybe = _.maybe.fromNullable(1); + const ex7: Maybe = _.maybe.fromNullable(null); + + const ex8: Maybe = _.maybe.fromResult(_.result.Ok(1)); + const ex9: Maybe = _.maybe.fromResult(_.result.Error("a")); + + const ex10: Maybe = _.maybe.fromValidation(_.validation.Success(1)); + const ex11: Maybe = _.maybe.fromValidation(_.validation.Failure("a")); + + const f = (x: number) => x.toString(); + + const ex12: Maybe = _.maybe.of(1).map(x => x.toString()); + const ex13: Maybe = _.maybe.of(f).apply(_.maybe.of(1)); + const ex14: Maybe = _.maybe.of(1).chain(x => _.maybe.of(x.toString())); + const ex15: number = _.maybe.of(1).getOrElse(2); + const ex15_: number = _.maybe.empty().getOrElse(2); + const ex16: Maybe = _.maybe.of(1).orElse(() => _.maybe.of(2)); + const ex17: Maybe = _.maybe.of('f').concat(_.maybe.of('g')); + const ex18: Maybe = _.maybe.of('f').filter(x => false); + const ex19: number = _.maybe.of(1).matchWith({ + Just: ({ value }) => value + 1, + Nothing: (_) => 0 + }); + const ex20: Result = _.maybe.of(1).toResult('f'); + const ex21: Validation = _.maybe.of(1).toValidation('g'); + + const ex22: string = _.maybe.of(1).inspect(); + const ex23: string = _.maybe.of(1).toString(); + + const ex24: boolean = _.maybe.of(1).equals(_.maybe.of(2)); + const ex25: string = _.maybe.of('foo').unsafeGet(); + const ex26: string = _.maybe.of(1).fold(f, () => 'g'); + const ex27: number = _.maybe.empty().fold((_) => 2, () => 3); +} +//#endregion + +//#region Result +{ + const ex1: Result = _.result.Error('foo'); + const ex2: Result = _.result.Ok('foo'); + const ex3: boolean = _.result.hasInstance(null); + const ex4: Result = _.result.of('foo'); + const ex5: Result = _.result.try(() => { throw 1 }); // not actually checked since TS doesn't have effects + const ex6: Result = _.result.try(() => 1); + + const ex7: Result = _.result.fromNullable('foo'); + const ex8: Result = _.result.fromNullable(null); + const ex9: Result = _.result.fromValidation(_.validation.Failure('foo')); + const ex10: Result = _.result.fromValidation(_.validation.Success('foo')); + const ex11: Result = _.result.fromMaybe(_.maybe.Nothing(), 'foo'); + const ex12: Result = _.result.fromMaybe(_.maybe.of(1), 'foo'); + + const ex13: Result<{}, string> = _.result.of(1).map(x => x.toString()); + const ex14: Result<{}, string> = _.result.of((x: number) => x.toString()).apply(_.result.of(1)); + const ex15: Result<{}, string> = _.result.of(1).chain(x => _.result.of(x.toString())); + const ex16: number = _.result.of(1).getOrElse(2); + const ex17: number = _.result.Error('foo').getOrElse(2); + const ex18: Result = _.result.Error(1).orElse(x => _.result.Ok(2)); + const ex19: Result<{}, string> = _.result.of('1').concat(_.result.of('2')); + const ex20: Result = _.result.of(1).swap(); + const ex21: Result<{}, number> = _.result.Error(1).swap(); + const ex22: Result<{}, string> = _.result.of(1).bimap(x => x, x => x.toString()); + const ex23: Result = _.result.Error(1).bimap(x => x.toString(), x => x); + const ex24: Result = _.result.Error(1).mapError(x => x.toString()); + const ex25: Result<{}, string> = _.result.of('f').filter(x => x.slice(0, 1) === 'f'); + const ex26: number = _.result.of(1).merge(); + const ex27: number | string = _.result.Error('f').merge(); + const ex28: Validation = _.result.Error('f').toValidation(); + const ex29: Validation<{}, string> = _.result.Ok('f').toValidation(); + const ex30: Maybe = _.result.Ok('f').toMaybe(); + const ex31: Maybe<{}> = _.result.Error('f').toMaybe(); + + const ex32: boolean = _.result.Ok(1).equals(_.result.Ok(2)); + const ex33: string = _.result.Ok(1).inspect(); + const ex34: string = _.result.Ok(1).toString(); + const ex35: string = _.result.Ok('f').unsafeGet(); + const ex36: number = _.result.Error('f').unsafeGet(); + const ex37: string = _.result.Ok(1).fold(x => '1', x => x.toString()); + const ex38: string = _.result.Error(1).fold(x => x.toString(), x => '3'); + const ex39: string = _.result.Ok(1).matchWith({ + Error: ({ value }) => 'f', + Ok: ({ value }) => value.toString() + }); + const ex40: string = _.result.Error(1).matchWith({ + Error: ({ value }) => value.toString(), + Ok: ({ value }) => 'f' + }); +} +//#endregion + + +//#region Validation +{ + const ex1: Validation = _.validation.Failure('foo'); + const ex2: Validation = _.validation.Success('foo'); + const ex3: boolean = _.validation.hasInstance(null); + const ex4: Validation = _.validation.of('foo'); + const ex5: Validation = _.validation.collect([ + _.validation.Failure('a'), + _.validation.Failure('b') + ]); + + + const ex7: Validation = _.validation.fromNullable('foo'); + const ex8: Validation = _.validation.fromNullable(null); + const ex9: Validation = _.validation.fromResult(_.result.Error('foo')); + const ex10: Validation = _.validation.fromResult(_.result.Ok('foo')); + const ex11: Validation = _.validation.fromMaybe(_.maybe.Nothing(), 'foo'); + const ex12: Validation = _.validation.fromMaybe(_.maybe.of(1), 'foo'); + + const ex13: Validation<{}, string> = _.validation.of(1).map(x => x.toString()); + const ex14: Validation = _.validation.of string>(x => x.toString()).apply(_.validation.of(1)); + const ex16: number = _.validation.of(1).getOrElse(2); + const ex17: number = _.validation.Failure('foo').getOrElse(2); + const ex18: Validation = _.validation.Failure(1).orElse(x => _.validation.Success(2)); + const ex19: Validation = _.validation.Failure('1').concat(_.validation.Failure('2')); + const ex20: Validation = _.validation.of(1).swap(); + const ex21: Validation<{}, number> = _.validation.Failure(1).swap(); + const ex22: Validation<{}, string> = _.validation.of(1).bimap(x => x, x => x.toString()); + const ex23: Validation = _.validation.Failure(1).bimap(x => x.toString(), x => x); + const ex24: Validation = _.validation.Failure(1).mapFailure(x => x.toString()); + const ex25: Validation<{}, string> = _.validation.of('f').filter(x => x.slice(0, 1) === 'f'); + const ex26: number = _.validation.of(1).merge(); + const ex27: number | string = _.validation.Failure('f').merge(); + const ex28: Result = _.validation.Failure('f').toResult(); + const ex29: Result<{}, string> = _.validation.Success('f').toResult(); + const ex30: Maybe = _.validation.Success('f').toMaybe(); + const ex31: Maybe<{}> = _.validation.Failure('f').toMaybe(); + + const ex32: boolean = _.validation.Success(1).equals(_.validation.Success(2)); + const ex33: string = _.validation.Success(1).inspect(); + const ex34: string = _.validation.Success(1).toString(); + const ex35: string = _.validation.Success('f').unsafeGet(); + const ex36: number = _.validation.Failure('f').unsafeGet(); + const ex37: string = _.validation.Success(1).fold(x => '1', x => x.toString()); + const ex38: string = _.validation.Failure(1).fold(x => x.toString(), x => '3'); + const ex39: string = _.validation.Success(1).matchWith({ + Failure: ({ value }) => 'f', + Success: ({ value }) => value.toString() + }); + const ex40: string = _.validation.Failure(1).matchWith({ + Failure: ({ value }) => value.toString(), + Success: ({ value }) => 'f' + }); +} +//#endregion \ No newline at end of file diff --git a/packages/base/tsconfig.json b/packages/base/tsconfig.json new file mode 100644 index 0000000..423785e --- /dev/null +++ b/packages/base/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "alwaysStrict": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "rootDir": "./", + "outDir": "./_build", + "pretty": true, + "moduleResolution": "node", + "sourceMap": true, + "target": "es2015", + "noEmitOnError": true, + "lib": [ + "es2017" + ], + "types": [ + "node" + ] + }, + "include": [ + "*.ts" + ] +} \ No newline at end of file From 49d1bfb7dcb7f3e5730eddba1c1a0b02d7735f33 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 10 Dec 2017 20:25:25 -0200 Subject: [PATCH 13/25] Types for Future --- packages/base/index.d.ts | 2 +- packages/base/test.ts | 42 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index cc3e28f..10e184f 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -261,7 +261,7 @@ declare namespace folktale { orElse(handler: (_: A) => Future): Future swap(): Future - apply(this: Future C>, that: Future): Future + apply(this: Future C>, that: Future): Future bimap(onRejected: (_: A) => C, onResolved: (_: B) => D): Future chain(f: (_: B) => Future): Future map(f: (_: B) => C): Future diff --git a/packages/base/test.ts b/packages/base/test.ts index 36cc042..f310947 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -1,5 +1,5 @@ import * as _ from './index'; -import { Maybe, Validation, Result } from './index'; +import { Maybe, Validation, Result, Future, Task } from './index'; //#region Core.Lambda { @@ -186,4 +186,42 @@ import { Maybe, Validation, Result } from './index'; Success: ({ value }) => 'f' }); } -//#endregion \ No newline at end of file +//#endregion + +//#region Futures +{ + const future = _.concurrency.future; + + const ex1: Future = future.of('a'); + const ex2: Future = future.rejected('a'); + const ex3: Future<{}, string> = future.fromPromise(Promise.resolve('a')); + + const ex4: Promise = future.of('a').toPromise(); + const ex5: string = future.of('a').inspect(); + const ex6: string = future.of(1).toString(); + + const ex7: Future<{}, string> = future.of(1).willMatchWith({ + Cancelled: () => future.of('nope'), + Resolved: (v) => future.of(v.toString()), + Rejected: (_) => future.of('nah') + }); + + const ex8: Future<{}, number> = future.of(1).listen({ + onCancelled: () => null, + onResolved: (v) => { v.toExponential() }, + onRejected: (_) => null + }); + + const ex9: Future = future.rejected(2).orElse(x => future.rejected(3)); + const ex10: Future = future.of(1).swap(); + const ex11: Future<{}, number> = future.rejected(1).swap(); + const ex12: Future<{}, string> = future.of((x: number) => x.toFixed()).apply(future.of(2)); + const ex13: Future<{}, string> = future.of(2).bimap(x => x, x => x.toFixed()); + const ex14: Future = future.rejected(2).bimap(x => x.toFixed(), x => x); + const ex15: Future<{}, string> = future.of(2).chain(x => future.of(x.toFixed())); + const ex16: Future<{}, string> = future.of(2).map(x => x.toFixed()); + const ex17: Future = future.rejected(2).mapRejected(x => x.toFixed()); + const ex18: Future = future.rejected(2).recover(x => future.rejected(x + 1)); +} +//#endregion + From ea9f79c583b6c18038a20aa5ed9b8a56ece12d75 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 16 Dec 2017 12:12:31 -0200 Subject: [PATCH 14/25] Removes overloaded operators TypeScript can't distinguish between them correctly :( --- packages/base/index.d.ts | 28 ++++------------------------ packages/base/test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 10e184f..25f1d6f 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -312,37 +312,17 @@ declare namespace folktale { } interface StaticTask { - waitAll(tasks: [Task, Task]): Task - waitAll(tasks: [Task, Task, Task]): Task - waitAll(tasks: [Task, Task, Task, Task]): Task - waitAll(tasks: [Task, Task, Task, Task, Task]): Task - waitAll(tasks: [Task, Task, Task, Task, Task, Task]): Task waitAll(tasks: Task[]): Task - waitAny(tasks: Task[]): Task - - + of(value: V): Task rejected(reason: E): Task - task(resolver: TaskResolver): Task - - fromNodeback(fn: (cb: (e: E, v: V) => void) => void): () => Task - fromNodeback(fn: (a1: A, cb: (e: E, v: V) => void) => void): (a1: A) => Task - fromNodeback(fn: (a1: A, a2: A2, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2) => Task - fromNodeback(fn: (a1: A, a2: A2, a3: A3, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3) => Task - fromNodeback(fn: (cb: (a1: A, a2: A2, a3: A3, a4: A4, e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4) => Task - fromNodeback(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Task - fromNodeback(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, cb: (e: E, v: V) => void) => void): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Task + task(resolver: (_: TaskResolver) => void): Task + fromNodeback(fn: (cb: (e: E, v: V) => void) => void): () => Task fromPromised(fn: () => Promise): () => Task - fromPromised(fn: (a1: A) => Promise): (a1: A) => Task - fromPromised(fn: (a1: A, a2: A2) => Promise): (a1: A, a2: A2) => Task - fromPromised(fn: (a1: A, a2: A2, a3: A3) => Promise): (a1: A, a2: A2, a3: A3) => Task - fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4) => Promise): (a1: A, a2: A2, a3: A3, a4: A4) => Task - fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Promise): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5) => Task - fromPromised(fn: (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Promise): (a1: A, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Task - do(generator: GeneratorFunction): Task + do(generator: () => IterableIterator>): Task } interface TaskResolver { diff --git a/packages/base/test.ts b/packages/base/test.ts index f310947..8a5a1d6 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -225,3 +225,34 @@ import { Maybe, Validation, Result, Future, Task } from './index'; } //#endregion +//#region Task +{ + const task = _.concurrency.task; + + const ex1: Task = task.of('a'); + const ex2: Task = task.rejected('a'); + const ex3: Task<{}, number[]> = task.waitAll([task.of(1), task.of(2)]); + const ex4: Task<{}, number> = task.waitAny([task.of(1), task.of(2)]); + const ex5: Task<{}, number> = task.of(1); + const ex6: Task = task.rejected(1); + const ex7: Task = task.task(r => { + r.resolve('a'); + r.reject(2); + r.cancel(); + const a: boolean = r.isCancelled; + r.cleanup(() => {}); + r.onCancelled(() => {}); + }); + + const ex8: () => Task = task.fromNodeback((cb: (e: never, v: number) => void) => {}); + const ex9: () => Task<{}, number> = task.fromPromised(() => Promise.resolve(1)); + + const ex10 = task.do(function* () { + const x: number = yield task.of(1); + return task.of(x); + }); + + + +} +//#endregion \ No newline at end of file From 06c4572ca3a92ddd1b53bb445bdf51905b34a42e Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 16 Dec 2017 14:49:24 -0200 Subject: [PATCH 15/25] Tests for Task + fix for .apply --- packages/base/index.d.ts | 2 +- packages/base/test.ts | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 25f1d6f..f664275 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -304,7 +304,7 @@ declare namespace folktale { orElse(handler: (_: A) => Task): Task swap(): Task - apply(this: Task B2>, that: Task): Task + apply(this: Task B2>, that: Task): Task bimap(onRejected: (_: A) => A2, onResolved: (_: B) => B2): Task chain(f: (_: B) => Task): Task map(f: (_: B) => B2): Task diff --git a/packages/base/test.ts b/packages/base/test.ts index 8a5a1d6..a5cb488 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -247,12 +247,31 @@ import { Maybe, Validation, Result, Future, Task } from './index'; const ex8: () => Task = task.fromNodeback((cb: (e: never, v: number) => void) => {}); const ex9: () => Task<{}, number> = task.fromPromised(() => Promise.resolve(1)); - const ex10 = task.do(function* () { + const ex10: Task<{}, number> = task.do(function* () { const x: number = yield task.of(1); return task.of(x); }); - + const ex11: Task<{}, [number, string]> = task.of(1).and(task.of('foo')); + const ex12: Task<{}, number> = task.of(1).or(task.of(2)); + const ex13: Task<{}, string> = task.of(1).willMatchWith({ + Cancelled: () => task.of('no'), + Resolved: (value) => task.of(value.toFixed()), + Rejected: (value) => task.rejected(value) + }); + const ex14: Task = task.rejected(1).willMatchWith({ + Cancelled: () => task.rejected(''), + Resolved: (value) => task.of(value), + Rejected: (value) => task.rejected(value.toFixed()) + }); + const ex15: Task = task.of(1).orElse(x => task.rejected(x.concat(x))); + const ex16: Task = task.of('foo').swap(); + const ex17: Task<{}, string> = task.of((x: number) => x.toFixed()).apply(task.of(1)); + const ex18: Task<{}, string> = task.of(1).bimap(x => x, x => x.toFixed()); + const ex19: Task = task.rejected(1).bimap(x => x.toFixed(), x => x); + const ex20: Task<{}, string> = task.of(1).chain(x => task.of(x.toFixed())); + const ex21: Task<{}, string> = task.of(1).map(x => x.toFixed()); + const ex22: Task = task.rejected(1).mapRejected(x => x.toFixed()); } //#endregion \ No newline at end of file From 3bdfba88d329fc232e58cc37b738ca69b981a83e Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 16 Dec 2017 15:09:59 -0200 Subject: [PATCH 16/25] Tests for conversions, remove overloaded conversions --- packages/base/index.d.ts | 16 ---------------- packages/base/test.ts | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index f664275..0d33e25 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -344,24 +344,8 @@ declare namespace folktale { resultToValidation(result: Result): Validation validationToMaybe(validation: Validation): Maybe validationToResult(validation: Validation): Result - - promisedToTask(fn: () => Promise): () => Task - promisedToTask(fn: (a: A1) => Promise): (a: A1) => Task - promisedToTask(fn: (a: A1, b: A2) => Promise): (a: A1, b: A2) => Task - promisedToTask(fn: (a: A1, b: A2, c: A3) => Promise): (a: A1, b: A2, c: A3) => Task - promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4) => Promise): (a: A1, b: A2, c: A3, d: A4) => Task - promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5) => Promise): (a: A1, b: A2, c: A3, d: A4, e: A5) => Task - promisedToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Promise): (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Task - nodebackToTask(fn: (cb: (error: E, value: V) => void) => void): () => Task - nodebackToTask(fn: (a: A1, cb: (error: E, value: V) => void) => void): (a: A1) => Task - nodebackToTask(fn: (a: A1, b: A2, cb: (error: E, value: V) => void) => void): (a: A1, b: A2) => Task - nodebackToTask(fn: (a: A1, b: A2, c: A3, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3) => Task - nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4) => Task - nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4, e: A5) => Task - nodebackToTask(fn: (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, cb: (error: E, value: V) => void) => void): (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6) => Task - nullableToMaybe(value: A | null | undefined): Maybe nullableToResult(value: A | null | undefined): Result nullableToValidation(value: A | null | undefined, fallback: B): Validation diff --git a/packages/base/test.ts b/packages/base/test.ts index a5cb488..10b413a 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -274,4 +274,26 @@ import { Maybe, Validation, Result, Future, Task } from './index'; const ex21: Task<{}, string> = task.of(1).map(x => x.toFixed()); const ex22: Task = task.rejected(1).mapRejected(x => x.toFixed()); } +//#endregion + +//#region Conversions +{ + const c = _.conversions; + + const ex1: Promise = c.futureToPromise(_.concurrency.future.of(1)); + const ex2: Result = c.maybeToResult(_.maybe.of(1), 'bar'); + const ex3: Validation = c.maybeToValidation(_.maybe.of(1), 'bar'); + const ex4: Future = c.promiseToFuture(Promise.resolve('f')); + const ex5: Maybe = c.resultToMaybe(_.result.of('f')); + const ex6: Validation<{}, string> = c.resultToValidation(_.result.Ok('f')); + const ex7: Validation = c.resultToValidation(_.result.Error(1)); + const ex8: Maybe = c.validationToMaybe(_.validation.Success('f')); + const ex9: Result<{}, number> = c.validationToResult(_.validation.Success(1)); + const ex10: Result = c.validationToResult(_.validation.Failure(1)); + const ex11: () => Task = c.promisedToTask(() => Promise.resolve(1)); + const ex12: () => Task = c.nodebackToTask((cb: (e: number, v: string) => void) => {}); + const ex13: Maybe = c.nullableToMaybe('2'); + const ex14: Result = c.nullableToResult(21); + const ex15: Validation = c.nullableToValidation('f', 34); +} //#endregion \ No newline at end of file From 71912806ab0f38c08d9b0ec9ebef0f510492aaac Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 17 Dec 2017 19:03:59 -0200 Subject: [PATCH 17/25] Updates types for nullableToResult --- packages/base/index.d.ts | 6 +++--- packages/base/test.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 0d33e25..122d352 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -163,7 +163,7 @@ declare namespace folktale { hasInstance(value: any): boolean; of(value: B): Result; try(f: (() => B)): Result; - fromNullable(value: B | null | undefined): Result; + fromNullable(value: B | null | undefined, fallback: A): Result; fromValidation(value: Validation): Result; fromMaybe(value: Maybe, failure: A): Result; } @@ -236,7 +236,7 @@ declare namespace folktale { hasInstance(value: any): boolean; of(value: B): Validation; collect>(validations: Validation[]): Validation; - fromNullable(value: B | null): Validation; + fromNullable(value: B | null | undefined, fallback: A): Validation; fromResult(value: Result): Validation; fromMaybe(value: Maybe, failure: A): Validation; } @@ -347,7 +347,7 @@ declare namespace folktale { promisedToTask(fn: () => Promise): () => Task nodebackToTask(fn: (cb: (error: E, value: V) => void) => void): () => Task nullableToMaybe(value: A | null | undefined): Maybe - nullableToResult(value: A | null | undefined): Result + nullableToResult(value: A | null | undefined, fallback: B): Result nullableToValidation(value: A | null | undefined, fallback: B): Validation } diff --git a/packages/base/test.ts b/packages/base/test.ts index 10b413a..689c134 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -86,8 +86,8 @@ import { Maybe, Validation, Result, Future, Task } from './index'; const ex5: Result = _.result.try(() => { throw 1 }); // not actually checked since TS doesn't have effects const ex6: Result = _.result.try(() => 1); - const ex7: Result = _.result.fromNullable('foo'); - const ex8: Result = _.result.fromNullable(null); + const ex7: Result = _.result.fromNullable('foo', 1); + const ex8: Result = _.result.fromNullable(null, 1); const ex9: Result = _.result.fromValidation(_.validation.Failure('foo')); const ex10: Result = _.result.fromValidation(_.validation.Success('foo')); const ex11: Result = _.result.fromMaybe(_.maybe.Nothing(), 'foo'); @@ -144,8 +144,8 @@ import { Maybe, Validation, Result, Future, Task } from './index'; ]); - const ex7: Validation = _.validation.fromNullable('foo'); - const ex8: Validation = _.validation.fromNullable(null); + const ex7: Validation = _.validation.fromNullable('foo', 1); + const ex8: Validation = _.validation.fromNullable(null, 1); const ex9: Validation = _.validation.fromResult(_.result.Error('foo')); const ex10: Validation = _.validation.fromResult(_.result.Ok('foo')); const ex11: Validation = _.validation.fromMaybe(_.maybe.Nothing(), 'foo'); @@ -293,7 +293,7 @@ import { Maybe, Validation, Result, Future, Task } from './index'; const ex11: () => Task = c.promisedToTask(() => Promise.resolve(1)); const ex12: () => Task = c.nodebackToTask((cb: (e: number, v: string) => void) => {}); const ex13: Maybe = c.nullableToMaybe('2'); - const ex14: Result = c.nullableToResult(21); + const ex14: Result = c.nullableToResult(21, 'error'); const ex15: Validation = c.nullableToValidation('f', 34); } //#endregion \ No newline at end of file From fc92ae711144a771c0cb47d0e1f6158adb15f288 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 17 Dec 2017 19:12:10 -0200 Subject: [PATCH 18/25] Adds changes to changelog --- packages/base/CHANGELOG.md | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/base/CHANGELOG.md b/packages/base/CHANGELOG.md index 8cf480c..954c37d 100644 --- a/packages/base/CHANGELOG.md +++ b/packages/base/CHANGELOG.md @@ -7,28 +7,39 @@ Each version entry is written as a heading in the format `[] - Y - **New features** — Functionality that has been added from the previous version to the referred one; - **Bug fixes** — Incorrect behaviour that has been corrected from the previous version to the referred one; - **Optimisations** — Performance and memory improvements from the previous version to the referred one; - - **Documentation** — Improvements made to the documentation; - - **Miscellaneous** — Any other change worth mentioning that doesn't fall in the previous ones; - **DEPRECATED FEATURES** — Features that have been deprecated in the referred version, and should be avoided for new codebases; - **BREAKING CHANGES** — Backwards-incompatible changes that have been introduced by the version, along with the changes necessary to existing codebases. Upgrading from previous versions is not safe; + - **Documentation** — Improvements made to the documentation; + - **Miscellaneous** — Any other change worth mentioning that doesn't fall in the previous ones; --- -## [2.0.1] - 2017-07-22 +## [2.1.0] - WIP -### Documentation +### New features + + - `nullableToResult` now takes a fallback value as argument ([PR #166](https://github.com/origamitower/folktale/pull/166) by @diasbruno) - - Many typos were fixed ([PR #151](https://github.com/origamitower/folktale/pull/151) by @gvillalta99; [PR #165](https://github.com/origamitower/folktale/pull/165) by @MichaelQQ, [PR #145](https://github.com/origamitower/folktale/pull/145) by @stabbylambda, [PR #143](https://github.com/origamitower/folktale/pull/143) and [PR #144](https://github.com/origamitower/folktale/pull/144) by @floriansimon1) - - Migration documentation on Task has been improved, and examples fixed ([PR #160](https://github.com/origamitower/folktale/pull/160)) - - Added notes on shims for older platforms ([PR #161](https://github.com/origamitower/folktale/pull/161)) - - Fixed some Validation examples ([PR #154](https://github.com/origamitower/folktale/pull/154) by @scotttrinh) + +### Bug fixes + + - Fixed handling objects without a `.toString` method in ADT's debug representation ([PR #169](https://github.com/origamitower/folktale/pull/169)) ### DEPRECATED FEATURES - Renamed `Future.recover` to `Future.orElse`. `Future.recover` was deprecated. ([PR #146](https://github.com/origamitower/folktale/pull/146)) + - Calling `nullableToResult` and `Result.fromNullable` with one argument is deprecated. An explicit fallback value should be provided. + + +### Documentation + + - Many typos were fixed ([PR #151](https://github.com/origamitower/folktale/pull/151) by @gvillalta99; [PR #165](https://github.com/origamitower/folktale/pull/165) by @MichaelQQ, [PR #145](https://github.com/origamitower/folktale/pull/145) by @stabbylambda, [PR #143](https://github.com/origamitower/folktale/pull/143) and [PR #144](https://github.com/origamitower/folktale/pull/144) by @floriansimon1) + - Migration documentation on Task has been improved, and examples fixed ([PR #160](https://github.com/origamitower/folktale/pull/160)) + - Added notes on shims for older platforms ([PR #161](https://github.com/origamitower/folktale/pull/161)) + - Fixed some Validation examples ([PR #154](https://github.com/origamitower/folktale/pull/154) by @scotttrinh) ### Miscellaneous From 903d15f68b5604b93e3d7604ce37092148bfb5b2 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 17 Dec 2017 19:12:17 -0200 Subject: [PATCH 19/25] Reorganises changelog --- packages/base/CHANGELOG.md | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/base/CHANGELOG.md b/packages/base/CHANGELOG.md index 954c37d..1cb68f8 100644 --- a/packages/base/CHANGELOG.md +++ b/packages/base/CHANGELOG.md @@ -104,12 +104,6 @@ Each version entry is written as a heading in the format `[] - Y ## [2.0.0-beta1] - 2017-05-03 -### Documentation - - - Documentation for Data.Future was added. - - Fixed some of the Data.Task documentation. - - ### New features - `nodebackToTask` (and `Task.fromNodeback`) allows converting callback-based functions in Node-style to Tasks automatically @@ -135,19 +129,14 @@ Each version entry is written as a heading in the format `[] - Y ``` +### Documentation + - Documentation for Data.Future was added. + - Fixed some of the Data.Task documentation. -## [2.0.0-alpha4] - 2017-04-08 -### Documentation - - - Guides for installing and contributing to Folktale were added. - - An annex describing the type annotation used in Folktale was added. - - Documentation for Data.Task was added. - - Other documentation improvements were made. - - Top-level async/await is now supported in Documentation examples. - - Experimental features now have a section noting such in their pages. +## [2.0.0-alpha4] - 2017-04-08 ### New features @@ -187,6 +176,17 @@ Each version entry is written as a heading in the format `[] - Y That said, you should keep your Failures as proper semigroups, so things like `.apply` and `.concat` will work correctly. +### Documentation + + - Guides for installing and contributing to Folktale were added. + - An annex describing the type annotation used in Folktale was added. + - Documentation for Data.Task was added. + - Other documentation improvements were made. + - Top-level async/await is now supported in Documentation examples. + - Experimental features now have a section noting such in their pages. + + + ## [2.0.0-alpha3] - 2017-03-11 ### New features @@ -209,12 +209,6 @@ Each version entry is written as a heading in the format `[] - Y ([d5b0c74](https://github.com/origamitower/folktale/commit/d5b0c7436717db442d3412b520e33339d9ad4002)); -### Miscellaneous - - - Annotated files are now only generated for testing and documentation, which makes browser bundles much smaller - ([e0186fa](https://github.com/origamitower/folktale/commit/e0186fa3779b98c5760fed0bc7546bbf6356ea4f)); - - ### DEPRECATED FEATURES - The old `.get()` methods are deprecated in favour of the new `.unsafeGet()` methods. There was no behavioural change, just a naming one. See [#42](https://github.com/origamitower/folktale/issues/42). @@ -290,6 +284,12 @@ Each version entry is written as a heading in the format `[] - Y - The `partialise` function (`core/lambda/partialise.js`) is now called `partialize` (`core/lambda/partialize.js`). +### Miscellaneous + + - Annotated files are now only generated for testing and documentation, which makes browser bundles much smaller + ([e0186fa](https://github.com/origamitower/folktale/commit/e0186fa3779b98c5760fed0bc7546bbf6356ea4f)); + + ## [2.0.0-alpha2] - 2016-12-05 ### New features From 9e9be1f98e584fb86a84f97678ef33a9ce6cef36 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 30 Dec 2017 16:02:42 -0200 Subject: [PATCH 20/25] Ignores bundle stuff --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b98e253..1d47768 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ npm-debug.log /annotations/build/ /docs/api/master/ /docs/_site/ +/docs/vendor/ /docs/.jekyll-metadata /test/build/ /tools/static-docs/lib/ From 20ee5e52988ed1a5c0d168c00fbf845a413c46ac Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sat, 30 Dec 2017 16:15:47 -0200 Subject: [PATCH 21/25] N-ary waitAll versions --- packages/base/index.d.ts | 5 +++ .../base/source/concurrency/task/index.js | 9 +++-- .../base/source/concurrency/task/wait-all.js | 8 +++++ packages/base/test.ts | 35 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 122d352..fdd8d44 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -313,6 +313,11 @@ declare namespace folktale { interface StaticTask { waitAll(tasks: Task[]): Task + waitAll2(a: Task, b: Task): Task + waitAll3(a: Task, b: Task, c: Task): Task + waitAll4(a: Task, b: Task, c: Task, d: Task): Task + waitAll5(a: Task, b: Task, c: Task, d: Task, e: Task): Task + waitAll6(a: Task, b: Task, c: Task, d: Task, e: Task, f: Task): Task waitAny(tasks: Task[]): Task of(value: V): Task diff --git a/packages/base/source/concurrency/task/index.js b/packages/base/source/concurrency/task/index.js index 322f84a..8d10da7 100644 --- a/packages/base/source/concurrency/task/index.js +++ b/packages/base/source/concurrency/task/index.js @@ -8,7 +8,7 @@ //---------------------------------------------------------------------- const Task = require('./_task'); - +const waitAll = require('./wait-all'); /*~ * stability: experimental @@ -19,7 +19,12 @@ module.exports = { rejected: Task.rejected, task: require('./task'), waitAny: require('./wait-any'), - waitAll: require('./wait-all'), + waitAll: waitAll, + waitAll2: waitAll._2, + waitAll3: waitAll._3, + waitAll4: waitAll._4, + waitAll5: waitAll._5, + waitAll6: waitAll._6, do: require('./do'), _Task: Task, _TaskExecution: require('./_task-execution'), diff --git a/packages/base/source/concurrency/task/wait-all.js b/packages/base/source/concurrency/task/wait-all.js index 0e2cc71..4d8b888 100644 --- a/packages/base/source/concurrency/task/wait-all.js +++ b/packages/base/source/concurrency/task/wait-all.js @@ -21,4 +21,12 @@ const waitAll = (tasks) => { ); }; + +waitAll._2 = (a, b) => waitAll([a, b]); +waitAll._3 = (a, b, c) => waitAll([a, b, c]); +waitAll._4 = (a, b, c, d) => waitAll([a, b, c, d]); +waitAll._5 = (a, b, c, d, e) => waitAll([a, b, c, d, e]); +waitAll._6 = (a, b, c, d, e, f) => waitAll([a, b, c, d, e, f]); + + module.exports = waitAll; diff --git a/packages/base/test.ts b/packages/base/test.ts index 689c134..7d1f6c3 100644 --- a/packages/base/test.ts +++ b/packages/base/test.ts @@ -273,6 +273,41 @@ import { Maybe, Validation, Result, Future, Task } from './index'; const ex20: Task<{}, string> = task.of(1).chain(x => task.of(x.toFixed())); const ex21: Task<{}, string> = task.of(1).map(x => x.toFixed()); const ex22: Task = task.rejected(1).mapRejected(x => x.toFixed()); + + const ex23: Task = task.waitAll2( + task.rejected('hello'), + task.of(<2>2) + ); + + const ex24: Task<{}, [1, 2, 3]> = task.waitAll3( + task.of(<1>1), + task.of(<2>2), + task.of(<3>3) + ); + + const ex25: Task<{}, [1, 2, 3, 4]> = task.waitAll4( + task.of(<1>1), + task.of(<2>2), + task.of(<3>3), + task.of(<4>4) + ); + + const ex26: Task<{}, [1, 2, 3, 4, 5]> = task.waitAll5( + task.of(<1>1), + task.of(<2>2), + task.of(<3>3), + task.of(<4>4), + task.of(<5>5) + ); + + const ex27: Task<{}, [1, 2, 3, 4, 5, 6]> = task.waitAll6( + task.of(<1>1), + task.of(<2>2), + task.of(<3>3), + task.of(<4>4), + task.of(<5>5), + task.of(<6>6) + ); } //#endregion From c9ab4a6add6e458f3f375b50bf2cf48c99de5ca9 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 31 Dec 2017 12:36:23 -0200 Subject: [PATCH 22/25] Bumps to 3.0.0-alpha5 --- packages/base/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/package.json b/packages/base/package.json index 51a9088..b4365f9 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,6 +1,6 @@ { "name": "folktale", - "version": "2.1.0-alpha3", + "version": "3.0.0-alpha5", "description": "A suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs and more reuse.", "main": "./index.js", "typings": "./index.d.ts", From 7ab9f10c94009d4c4ee818d80600379d46227c31 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 18 Feb 2018 18:28:58 -0300 Subject: [PATCH 23/25] Fixes type for Maybe.fold --- packages/base/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index fdd8d44..92a9f01 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -56,7 +56,7 @@ declare namespace folktale { toString(): string; equals(that: Maybe): boolean; unsafeGet(): A; - fold(onJust: (_: A) => B, onNothing: () => B): B; + fold(onNothing: () => B, onJust: (_: A) => B): B; } interface Nothing { @@ -79,7 +79,7 @@ declare namespace folktale { toString(): string; equals(that: Maybe): boolean; unsafeGet(): A; - fold(onJust: (_: A) => B, onNothing: () => B): B; + fold(onNothing: () => B, onJust: (_: A) => B): B; } interface StaticMaybe { From e3e947abfdb120011c8be2162b0606ff0de7f038 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 18 Feb 2018 18:30:23 -0300 Subject: [PATCH 24/25] Includes undefined in Maybe.fromNullable --- packages/base/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/index.d.ts b/packages/base/index.d.ts index 92a9f01..42c3242 100644 --- a/packages/base/index.d.ts +++ b/packages/base/index.d.ts @@ -88,7 +88,7 @@ declare namespace folktale { Just(value: A): Maybe; Nothing(): Maybe; hasInstance(value: any): boolean; - fromNullable(_: A | null): Maybe; + fromNullable(_: A | null | undefined): Maybe; fromResult(_: Result): Maybe; fromValidation(_: Validation): Maybe; } From 719fbb75c81630e85ef5672fd079fe545da76898 Mon Sep 17 00:00:00 2001 From: Quildreen Motta Date: Sun, 18 Feb 2018 18:32:42 -0300 Subject: [PATCH 25/25] Bumps to 3.0.1-ts --- packages/base/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base/package.json b/packages/base/package.json index b4365f9..903f6e1 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,6 +1,6 @@ { "name": "folktale", - "version": "3.0.0-alpha5", + "version": "3.0.1-ts", "description": "A suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs and more reuse.", "main": "./index.js", "typings": "./index.d.ts",