Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change exo6 variable name #154

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/exo6 - ReaderTaskEither/exo6.exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const getConcatenationOfTheTwoUserNamesUsingAp: (args: {
// and bind the return value to feed the context and use this data.

export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
userIdOne: string;
userId: string;
}) => ReaderTaskEither<
User.Repository.Access,
User.Repository.UserNotFoundError,
Expand All @@ -95,7 +95,7 @@ export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
type Dependencies = User.Repository.Access & Application.TimeService.Access;

export const getConcatenationOfUserNameAndCurrentYear: (args: {
userIdOne: string;
userId: string;
}) => ReaderTaskEither<
Dependencies,
User.Repository.UserNotFoundError,
Expand Down
20 changes: 10 additions & 10 deletions src/exo6 - ReaderTaskEither/exo6.solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,33 @@ export const getConcatenationOfTheTwoUserNamesUsingAp = ({
// and bind the return value to feed the context and use this data.

export const getConcatenationOfTheBestFriendNameAndUserName = ({
userIdOne,
userId,
}: {
userIdOne: string;
userId: string;
}) =>
pipe(
rte.Do,
rte.apS('userOne', User.Repository.getById(userIdOne)),
rte.bind('userTwo', ({ userOne }) =>
User.Repository.getById(userOne.bestFriendId),
rte.apS('user', User.Repository.getById(userId)),
rte.bind('bestFriend', ({ user }) =>
User.Repository.getById(user.bestFriendId),
),
rte.map(
({ userOne, userTwo }) =>
`${capitalize(userOne.name)}${capitalize(userTwo.name)}`,
({ user, bestFriend }) =>
`${capitalize(user.name)}${capitalize(bestFriend.name)}`,
),
);

// Most of the time, you will need to use several external services.
// The challenge of this use-case is to use TimeService in the flow of our `rte`

export const getConcatenationOfUserNameAndCurrentYear = ({
userIdOne,
userId,
}: {
userIdOne: string;
userId: string;
}) =>
pipe(
rte.Do,
rte.apS('user', User.Repository.getById(userIdOne)),
rte.apS('user', User.Repository.getById(userId)),
rte.apSW('year', rte.fromReader(Application.TimeService.thisYear())),
rte.map(({ user, year }) => `${user.name}${year}`),
);
4 changes: 2 additions & 2 deletions src/exo6 - ReaderTaskEither/exo6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('exo6', () => {

it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
const usecase = getConcatenationOfTheBestFriendNameAndUserName({
userIdOne: '1',
userId: '1',
})({
userRepository: new User.Repository.InMemoryUserRepository([
{ id: '1', name: 'rob', bestFriendId: '2' },
Expand All @@ -77,7 +77,7 @@ describe('exo6', () => {
const timeservice = new Application.NodeTimeService.NodeTimeService();

const usecase = getConcatenationOfUserNameAndCurrentYear({
userIdOne: '1',
userId: '1',
})({
userRepository: new User.Repository.InMemoryUserRepository([
{ id: '1', name: 'rob', bestFriendId: '2' },
Expand Down