Ex6 fixes (#108)

* improve comments readability

* fix name of function to clarify expectation

* fix inaccurate expectation
This commit is contained in:
Brian Valette 2022-12-28 09:26:52 +01:00 committed by GitHub
parent f5babc5737
commit e11c1b34c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 17 deletions

View File

@ -5,7 +5,7 @@ import {
getCapitalizedUserName,
getConcatenationOfTheBestFriendNameAndUserName,
getConcatenationOfTheTwoUserNames,
getConcatenationOfUserNameAndYear,
getConcatenationOfUserNameAndCurrentYear,
} from './exo6';
describe('exo6', () => {
@ -34,7 +34,7 @@ describe('exo6', () => {
const result = await usecase();
expect(result).toEqual(either.right('robscott'));
expect(result).toEqual(either.right('RobScott'));
});
it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
@ -49,13 +49,13 @@ describe('exo6', () => {
const result = await usecase();
expect(result).toEqual(either.right('robscott'));
expect(result).toEqual(either.right('RobScott'));
});
it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
it('should return the concatenation of the user name and the current year', async () => {
const timeservice = new Application.NodeTimeService.NodeTimeService();
const usecase = getConcatenationOfUserNameAndYear({
const usecase = getConcatenationOfUserNameAndCurrentYear({
userIdOne: '1',
})({
userRepository: new User.Repository.InMemoryUserRepository([

View File

@ -6,7 +6,8 @@ import { unimplemented } from '../utils';
import { Application } from './application';
import { User } from './domain';
// In real world applications you will mostly manipulate `ReaderTaskEither` aka `rte` in the use-cases of the application.
// In real world applications you will mostly manipulate `ReaderTaskEither` aka
// `rte` in the use-cases of the application.
// `Reader` -> For dependency injection
// `Task` -> For async operation
// `Either` -> For computations that may fail
@ -18,8 +19,10 @@ import { User } from './domain';
// You will learn the usage of the most common in the following usecases.
// In the following usecase, you will learn the usage of `rte.map()`.
// `rte.map()` allows you to perform an operation on the values stored in the current context.
// In the following example, we need to fetch a user by its id and then we want to return its capitalized.
// `rte.map()` allows you to perform an operation on the values stored in the
// current context. In the following example, we need to fetch a user by its id
// and then we want to return its capitalized.
export const getCapitalizedUserName: (args: {
userId: string;
@ -29,11 +32,12 @@ export const getCapitalizedUserName: (args: {
string
> = unimplemented;
// Sometimes you will need to get multiple data before performing an operation on them.
// In this case, it is very convenient to use the `Do` notation.
// Sometimes you will need to get multiple data before performing an operation
// on them. In this case, it is very convenient to use the `Do` notation.
//
// The `Do` notation allows you to enrich the context step-by-step by binding the result
// of an effect (in this case a RTE) to a named variable using `rte.apS` or `rte.apSW`.
// The `Do` notation allows you to enrich the context step-by-step by binding
// the result of an effect (in this case a RTE) to a named variable using
// `rte.apS` or `rte.apSW`.
//
// For example:
// pipe(
@ -51,10 +55,14 @@ export const getConcatenationOfTheTwoUserNames: (args: {
string
> = unimplemented;
// Sometimes, you will need to feed the current context with data that you can only retrieve after performing some operations.
// For example, if you want to fetch the best friend of a user you will have to fetch the first user and then fetch its bestfriend.
// In this case, we will use `rte.bindW()` to use data of the current context (the firstly fetched user)
// to perform a second operation (fetch its bestfriend) and bind the return value to feed the context and use those data.
// Sometimes, you will need to feed the current context with data that you can
// only retrieve after performing some operations, in other words, operations
// need to be sequential.
// For example, if you want to fetch the best friend of a user you will have to
// fetch the first user and then fetch its best friend.
// In this case, we will use `rte.bindW()` to use data of the current context
// (the firstly fetched user) to perform a second operation (fetch its best friend)
// and bind the return value to feed the context and use those data.
export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
userIdOne: string;
@ -68,7 +76,7 @@ export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
// The challenge of this usecase is to use TimeService in the flow of our `rte`
type Dependencies = User.Repository.Access & Application.TimeService.Access;
export const getConcatenationOfUserNameAndYear: (args: {
export const getConcatenationOfUserNameAndCurrentYear: (args: {
userIdOne: string;
}) => ReaderTaskEither<
Dependencies,