Skip to content

Commit

Permalink
Remove superfluous lifts #380
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Mar 8, 2021
1 parent bb9b689 commit e2d5f53
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions scripts/find-reviews-from-ncrc.ts
Expand Up @@ -45,7 +45,7 @@ void (async (): Promise<void> => {
}),
constant('unavailable' as const),
)),
T.map(E.chain(flow(
TE.chainEitherK(flow(
(res) => res?.data?.values,
O.fromNullable,
O.map(flow(
Expand All @@ -54,7 +54,7 @@ void (async (): Promise<void> => {
RA.filter((row) => /(biorxiv|medrxiv)/i.test(row.journal)),
)),
E.fromOption(constant('unavailable' as const)),
))),
)),
T.map(E.fold(
() => {
process.stderr.write('error');
Expand Down
21 changes: 11 additions & 10 deletions src/home-page/render-feed.ts
@@ -1,8 +1,10 @@
import * as E from 'fp-ts/Either';
import * as O from 'fp-ts/Option';
import * as T from 'fp-ts/Task';
import * as TE from 'fp-ts/TaskEither';
import * as B from 'fp-ts/boolean';
import { constant, pipe } from 'fp-ts/function';
import { constant, flow, pipe } from 'fp-ts/function';
import { identity } from 'io-ts';
import { HtmlFragment, toHtmlFragment } from '../types/html-fragment';
import { UserId } from '../types/user-id';

Expand Down Expand Up @@ -50,10 +52,10 @@ const renderAsSection = (contents: HtmlFragment) => toHtmlFragment(`
</section>
`);

export const renderFeed = <E>(
export const renderFeed = <Err>(
isFollowingSomething: IsFollowingSomething,
getEvents: GetEvents<E>,
renderSummaryFeedList: RenderSummaryFeedList<E>,
getEvents: GetEvents<Err>,
renderSummaryFeedList: RenderSummaryFeedList<Err>,
): RenderFeed => (uid) => pipe(
uid,
TE.fromOption(constant(welcomeMessage)),
Expand All @@ -75,10 +77,9 @@ export const renderFeed = <E>(
(summaryFeedList) => TE.right(summaryFeedList),
),
),
TE.fold(
(left) => T.of(left),
(right) => T.of(right),
),
T.map(toHtmlFragment),
T.map(renderAsSection),
T.map(flow(
E.fold(identity, identity),
toHtmlFragment,
renderAsSection,
)),
);
6 changes: 2 additions & 4 deletions src/infrastructure/fetch-datacite-review.ts
Expand Up @@ -28,15 +28,14 @@ const fetchReviewContent = (
async () => fetchDataset(reviewIri),
constant('unavailable' as const), // TODO might be 'not-found'
),
TE.chain(flow(
TE.chainEitherK(flow(
(graph) => graph.out(schema.description).value,
E.fromNullable('unavailable' as const),
E.map(toHtmlFragment),
E.map((fullText) => ({
fullText,
url: new URL(reviewIri.value),
})),
TE.fromEither,
)),
TE.map((review) => {
logger('debug', 'Retrieved review', { review });
Expand All @@ -53,7 +52,6 @@ export const fetchDataciteReview = (fetchDataset: FetchDataset, logger: Logger):
return url;
},
namedNode,
TE.right,
TE.chain((reviewIri) => fetchReviewContent(fetchDataset, logger, reviewIri)),
(reviewIri) => fetchReviewContent(fetchDataset, logger, reviewIri),
)
);
3 changes: 1 addition & 2 deletions src/infrastructure/fetch-ncrc-review.ts
Expand Up @@ -142,8 +142,7 @@ const getNcrcReview = (logger: Logger) => (rowNumber: number) => pipe(
);

export const fetchNcrcReview = (logger: Logger): FetchNcrcReview => flow(
TE.right,
TE.chain(getRowNumber(logger)),
getRowNumber(logger),
TE.chainW(getNcrcReview(logger)),
TE.map(constructNcrcReview),
);
5 changes: 2 additions & 3 deletions src/infrastructure/get-article-version-events-from-biorxiv.ts
Expand Up @@ -35,10 +35,9 @@ const makeRequest = (doi: Doi, server: ArticleServer) => ({ getJson, logger }: D
async () => getJson(`https://api.biorxiv.org/details/${server}/${doi.value}`),
E.toError,
),
TE.chain(flow(
TE.chainEitherK(flow(
biorxivArticleDetails.decode,
TE.fromEither,
TE.mapLeft((e) => new Error(PR.failure(e).join('\n'))),
E.mapLeft((errors) => new Error(PR.failure(errors).join('\n'))),
)),
TE.swap,
TE.chainFirstW(flow(
Expand Down
5 changes: 2 additions & 3 deletions src/infrastructure/get-events-from-database.ts
Expand Up @@ -27,9 +27,8 @@ export const getEventsFromDatabase = (
TE.right,
)),
TE.map(RA.map((row) => ({ ...row, ...row.payload }))),
TE.chain(flow(
TE.chainEitherK(flow(
domainEvents.decode,
TE.fromEither,
TE.mapLeft((errors) => new Error(PR.failure(errors).join('\n'))),
E.mapLeft((errors) => new Error(PR.failure(errors).join('\n'))),
)),
);

0 comments on commit e2d5f53

Please sign in to comment.