From f867fef92d59eac2825d1d35e2bec5b6fae97c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Th=C3=A9ron?= Date: Fri, 12 May 2023 17:35:11 +0200 Subject: [PATCH] Rename `apEitherK` to `apSEitherK` + fix some typos (#127) * exo8: ap -> apS * Fix typos --- src/exo0/exo0.ts | 2 +- src/exo1/exo1.ts | 6 ++---- src/exo2/exo2.ts | 4 ++-- src/exo5/exo5.ts | 8 +++++--- src/exo6/exo6.ts | 11 +++++------ src/exo7/exo7.ts | 14 +++++++------- src/exo8/exo8.test.ts | 16 ++++++++-------- src/exo8/exo8.ts | 12 ++++++------ 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/exo0/exo0.ts b/src/exo0/exo0.ts index 7a7fc7c..dab5136 100644 --- a/src/exo0/exo0.ts +++ b/src/exo0/exo0.ts @@ -2,7 +2,7 @@ // Composing computations with `pipe` and `flow` // Functional programming is all about composing small functions together like -// lego bricks to build more and more complex computations. +// Lego bricks to build more and more complex computations. // // Strictly speaking, composing two functions `f` and `g` means applying the // result of the first one to the second one. By applying this composition diff --git a/src/exo1/exo1.ts b/src/exo1/exo1.ts index 08ec470..9278168 100644 --- a/src/exo1/exo1.ts +++ b/src/exo1/exo1.ts @@ -20,24 +20,22 @@ export const divide = (a: number, b: number): number => { // Write the safe version (meaning it handles the case where b is 0) of `divide` with signature: // safeDivide : (a: number, b: number) => Option // -// HINT: Option has two basic contructors: +// HINT: Option has two basic constructors: // - `option.some(value)` // - `option.none` export const safeDivide: (a: number, b: number) => Option = unimplemented; - // You probably wrote `safeDivide` using `if` statements and it's perfectly valid! // There are ways to not use `if` statements. -// Keep in mind that extracting small functions out of pipes and using `if` statements in them +// Keep in mind that extracting small functions out of pipes and using `if` statements in them // is perfectly fine and is sometimes more readable than not using `if`. // // BONUS: Try now to re-write `safeDivide` without any `if` // // HINT: Have a look at `fromPredicate` constructor - /////////////////////////////////////////////////////////////////////////////// // EITHER // /////////////////////////////////////////////////////////////////////////////// diff --git a/src/exo2/exo2.ts b/src/exo2/exo2.ts index 9624614..b6cd038 100644 --- a/src/exo2/exo2.ts +++ b/src/exo2/exo2.ts @@ -10,7 +10,7 @@ import { unimplemented } from '../utils'; // SETUP // /////////////////////////////////////////////////////////////////////////////// -// We are developping a small game, and the player can control either one of +// We are developing a small game, and the player can control either one of // three types of characters, mainly differentiated by the type of damage they // can put out. @@ -133,7 +133,7 @@ export const checkTargetAndShoot: ( // OPTION // /////////////////////////////////////////////////////////////////////////////// -// The next three function take a `Character` and optionally return the +// The next three functions take a `Character` and optionally return the // expected damage type if the unit matches the expected character type. // // HINT: These functions represent the public API. But it is heavily diff --git a/src/exo5/exo5.ts b/src/exo5/exo5.ts index 7527eb3..36619ea 100644 --- a/src/exo5/exo5.ts +++ b/src/exo5/exo5.ts @@ -76,6 +76,7 @@ export const naiveGiveCurrencyOfCountryToUser = ( task.map(getCountryCode), task.map(option.map(getCountryCurrency)), ); + // The result type of this method is: `Task>>` // Not ideal, right? We would need to await the first `Task`, then check if it's // `Some` to get the `Task` inside and finally await the `Task` to retrieve the @@ -103,7 +104,7 @@ export const getCountryCurrencyOfOptionalCountryCode: ( // `Task>` // // HINT: You should be able to copy the pipe from naiveGiveCurrencyOfCountryToUser -// and make only few updates of it. `task.chain` helper may be usefull. +// and make only few updates of it. The `task.chain` helper may be useful. export const giveCurrencyOfCountryToUser: ( countryNameFromUserMock: string, @@ -123,6 +124,7 @@ export const giveCurrencyOfCountryToUser: ( export const getCountryCodeOfCountryNames = ( countryNames: ReadonlyArray, ) => countryNames.map(getCountryCode); + // As expected, we end up with a `ReadonlyArray>`. We know for // each item of the array if we have been able to find the corresponding country // code or not. @@ -134,7 +136,7 @@ export const getCountryCodeOfCountryNames = ( // Doing this allows you to stop the process if you have a `None` to tell the user // that some countries are not valid or move on with a `ReadonlyArray>` // if all are valid. -// Typewise, it means going from `ReadonlyArray>` to +// Type-wise, it means going from `ReadonlyArray>` to // `Option>` // This is what traversing array is about. @@ -208,7 +210,7 @@ export const performAsyncComputationInSequence: ( // `Option` in our example) // Sometimes, you just have two nested containers that you want to 'invert'. It // can be because the order of containers is meaningful (like `Either