From a6fe1bff194383cbbfac9ead43fe76f0db08a97e Mon Sep 17 00:00:00 2001 From: Roberto Tonino Date: Tue, 11 May 2021 20:31:21 +0200 Subject: [PATCH] chore: removed IO functor --- server/src/functors/IO.ts | 38 --------------------- server/src/helpers/errors.ts | 8 ++--- server/src/routes/api/get/getChartTracks.ts | 2 +- 3 files changed, 3 insertions(+), 45 deletions(-) delete mode 100644 server/src/functors/IO.ts diff --git a/server/src/functors/IO.ts b/server/src/functors/IO.ts deleted file mode 100644 index ccc4dd6..0000000 --- a/server/src/functors/IO.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { compose } from 'ramda' - -// https://mostly-adequate.gitbook.io/mostly-adequate-guide/appendix_b#io -export class IO { - public unsafePerformIO: any - - constructor(fn: any) { - this.unsafePerformIO = fn - } - - // [util.inspect.custom]() { - // return 'IO(?)'; - // } - - // ----- Pointed IO - static of(x: any) { - return new IO(() => x) - } - - // ----- Functor IO - map(fn: any) { - return new IO(compose(fn, this.unsafePerformIO)) - } - - // ----- Applicative IO - ap(f: any) { - return this.chain((fn: any) => f.map(fn)) - } - - // ----- Monad IO - chain(fn: any) { - return this.map(fn).join() - } - - join() { - return new IO(() => this.unsafePerformIO().unsafePerformIO()) - } -} diff --git a/server/src/helpers/errors.ts b/server/src/helpers/errors.ts index 84760bf..14793e2 100644 --- a/server/src/helpers/errors.ts +++ b/server/src/helpers/errors.ts @@ -1,12 +1,8 @@ -import { compose, concat, map } from 'ramda' -import { IO } from '../functors/IO' - -export const consoleErrorIo = IO.of(console.error) +import { concat } from 'ramda' const prependDeemix = concat('[deemix-server]: ') -export const consoleError = (errorText: string) => - map((fn: any) => compose(fn, prependDeemix)(errorText), consoleErrorIo) +export const consoleError = (errorText: string) => console.error(prependDeemix(errorText)) export class BadRequestError extends Error { constructor() { diff --git a/server/src/routes/api/get/getChartTracks.ts b/server/src/routes/api/get/getChartTracks.ts index f2a0483..cd0468c 100644 --- a/server/src/routes/api/get/getChartTracks.ts +++ b/server/src/routes/api/get/getChartTracks.ts @@ -33,7 +33,7 @@ const handler: RequestHandler<{}, {}, {}, RawChartTracksQuery> = async (req, res next() } catch (error) { if (isBadRequestError(error)) { - consoleError(error.message).unsafePerformIO() + consoleError(error.message) res.status(400).send() return next() }