chore: removed IO functor
This commit is contained in:
parent
9fc36abf06
commit
a6fe1bff19
@ -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())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,8 @@
|
|||||||
import { compose, concat, map } from 'ramda'
|
import { concat } from 'ramda'
|
||||||
import { IO } from '../functors/IO'
|
|
||||||
|
|
||||||
export const consoleErrorIo = IO.of(console.error)
|
|
||||||
|
|
||||||
const prependDeemix = concat('[deemix-server]: ')
|
const prependDeemix = concat('[deemix-server]: ')
|
||||||
|
|
||||||
export const consoleError = (errorText: string) =>
|
export const consoleError = (errorText: string) => console.error(prependDeemix(errorText))
|
||||||
map((fn: any) => compose(fn, prependDeemix)(errorText), consoleErrorIo)
|
|
||||||
|
|
||||||
export class BadRequestError extends Error {
|
export class BadRequestError extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -33,7 +33,7 @@ const handler: RequestHandler<{}, {}, {}, RawChartTracksQuery> = async (req, res
|
|||||||
next()
|
next()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isBadRequestError(error)) {
|
if (isBadRequestError(error)) {
|
||||||
consoleError(error.message).unsafePerformIO()
|
consoleError(error.message)
|
||||||
res.status(400).send()
|
res.status(400).send()
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user