Fix typos (#23)
* ✏️ Fix typos in exo0 * ✏️ Fix typos in exo1 * ✏️ Fix typo in exo2 * ✏️ Fix typo on "Exercise"
This commit is contained in:
parent
eee540212f
commit
db715ba88c
7 changed files with 22 additions and 21 deletions
|
@ -3,10 +3,10 @@
|
|||
This repo is a work in progress toward having a comprehensive training material
|
||||
to onboard people on using `fp-ts` efficiently.
|
||||
|
||||
The exercices consist of unimplemented functions and their associated failing
|
||||
The exercises consist of unimplemented functions and their associated failing
|
||||
tests.
|
||||
|
||||
But first, it is essential to understand why we are using `fp-ts`. I suggest you read this [article](https://medium.com/inato/our-journey-to-functional-programing-36854a370de1) and then start the exercices.
|
||||
But first, it is essential to understand why we are using `fp-ts`. I suggest you read this [article](https://medium.com/inato/our-journey-to-functional-programing-36854a370de1) and then start the exercises.
|
||||
|
||||
To run the tests, simply run
|
||||
|
||||
|
@ -20,14 +20,14 @@ You can also run them in watch mode:
|
|||
$ yarn test:watch
|
||||
```
|
||||
|
||||
Finally, if you wish to only run the tests for a given exercice `exoN`, you can
|
||||
Finally, if you wish to only run the tests for a given exercise `exoN`, you can
|
||||
run the following:
|
||||
|
||||
```sh
|
||||
$ yarn test[:watch] exoN
|
||||
```
|
||||
|
||||
The exercices are organized into `exoN` folders and most of what is required to
|
||||
The exercises are organized into `exoN` folders and most of what is required to
|
||||
complete each is detailed in the comments.
|
||||
|
||||
## code style guide
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
// result of the first one to the second one. By applying this composition
|
||||
// over and over you can chain multiple functions together.
|
||||
//
|
||||
// The `fp-ts` library provides to helpers to do that:
|
||||
// The `fp-ts` library provides helpers to do that:
|
||||
// - `pipe` which first needs to be fed a value to start the pipe and then
|
||||
// any number of functions to be applied sequentially.
|
||||
// - `flow` which is the same thing but were we do not have to provide the
|
||||
// - `flow` which is the same thing but where we do not have to provide the
|
||||
// first value. It will then return a function which will expect that value
|
||||
// to be provided
|
||||
//
|
||||
|
@ -55,11 +55,12 @@ export const isOddF: (value: number) => boolean = unimplemented;
|
|||
//
|
||||
// Below is the functional equivalent of the control flow statement if-else.
|
||||
|
||||
export const ifThenElse = <A>(onTrue: () => A, onFalse: () => A) => (
|
||||
condition: boolean,
|
||||
) => (condition ? onTrue() : onFalse());
|
||||
export const ifThenElse =
|
||||
<A>(onTrue: () => A, onFalse: () => A) =>
|
||||
(condition: boolean) =>
|
||||
condition ? onTrue() : onFalse();
|
||||
|
||||
// Using `pipe` the function that computes the next step in the Collatz
|
||||
// Using `pipe`, write the function that computes the next step in the Collatz
|
||||
// sequence.
|
||||
|
||||
export const next: (value: number) => number = unimplemented;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// `fp-ts` training Exercice 1
|
||||
// `fp-ts` training Exercise 1
|
||||
// Basic types:
|
||||
// - Option
|
||||
// - Either
|
||||
|
@ -17,7 +17,7 @@ export const divide = (a: number, b: number): number => {
|
|||
// OPTION //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Write the safe version of `divide` whith signature:
|
||||
// Write the safe version of `divide` with signature:
|
||||
// safeDivide : (a: number, b: number) => Option<number>
|
||||
//
|
||||
// HINT: Option has two basic contructors:
|
||||
|
@ -31,7 +31,7 @@ export const safeDivide: (a: number, b: number) => Option<number> =
|
|||
// EITHER //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Write the safe version of `divide` whith signature:
|
||||
// Write the safe version of `divide` with signature:
|
||||
// safeDivideWithError : (a: number, b: number) => Either<DivideByZeroError, number>
|
||||
//
|
||||
// BONUS POINT: Implement `safeDivideWithError` in terms of `safeDivide`.
|
||||
|
@ -67,7 +67,7 @@ export const asyncDivide = async (a: number, b: number) => {
|
|||
return a / b;
|
||||
};
|
||||
|
||||
// Write the safe version of `divide` whith signature:
|
||||
// Write the safe version of `divide` with signature:
|
||||
// asyncSafeDivideWithError : (a: number, b: number) => TaskEither<DivideByZeroError, number>
|
||||
//
|
||||
// HINT: TaskEither has a special constructor to transform a Promise<T> into
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// `fp-ts` training Exercice 2
|
||||
// `fp-ts` training Exercise 2
|
||||
// Let's have fun with combinators!
|
||||
|
||||
import { Either } from 'fp-ts/Either';
|
||||
|
@ -133,7 +133,7 @@ export const checkTargetAndShoot: (
|
|||
// OPTION //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// The next three function take a `Character` and optionnaly return the
|
||||
// The next three function take a `Character` and optionally return the
|
||||
// expected damage type if the unit match the expected character type.
|
||||
//
|
||||
// HINT: These functions represent the public API. But it is heavily
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// `fp-ts` training Exercice 3
|
||||
// `fp-ts` training Exercise 3
|
||||
// Sort things out with `Ord`
|
||||
|
||||
import { Option } from 'fp-ts/Option';
|
||||
|
@ -12,7 +12,7 @@ import { unimplemented } from '../utils';
|
|||
// The difference with JavaScript's native `Array.prototype` methods is that
|
||||
// these are more `fp-ts` friendly.
|
||||
//
|
||||
// In the following exercice, we will take a look at `array.sort`. Contrary to
|
||||
// In the following exercise, we will take a look at `array.sort`. Contrary to
|
||||
// its JavaScript counterpart, `fp-ts` sort takes as an argument something of
|
||||
// type `Ord<T>` where `T` is the type of elements contained in the collection.
|
||||
//
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// `fp-ts` training Exercice 4
|
||||
// `fp-ts` training Exercise 4
|
||||
// Dependency injection with `Reader`
|
||||
|
||||
import { Reader } from 'fp-ts/Reader';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// `fp-ts` training Exercice 5
|
||||
// `fp-ts` training Exercise 5
|
||||
// Managing nested effectful data with `traverse`
|
||||
|
||||
import { option, readonlyRecord, task } from 'fp-ts';
|
||||
|
@ -224,5 +224,5 @@ export const sequenceOptionArray: (
|
|||
arrayOfOptions: ReadonlyArray<Option<CountryCode>>,
|
||||
) => Option<ReadonlyArray<CountryCode>> = unimplemented;
|
||||
|
||||
// BONUS: try using these two functions in the exercices 'TRAVERSING OPTIONS'
|
||||
// BONUS: try using these two functions in the exercises 'TRAVERSING OPTIONS'
|
||||
// and 'TRAVERSING ARRAYS' above
|
||||
|
|
Reference in a new issue