diff --git a/src/main/IO.ts b/src/main/IO.ts index 4dc7e7e8..d3ea333f 100644 --- a/src/main/IO.ts +++ b/src/main/IO.ts @@ -56,11 +56,7 @@ export class IO implements FIO { * Accesses an environment for the effect */ public static access(fn: (env: R) => A): IO { - return IO.to( - C((env1, rej, res) => { - res(fn(env1)) - }) - ) + return IO.from((env1, rej, res) => res(fn(env1))) } /** @@ -79,7 +75,7 @@ export class IO implements FIO { public static encase( fn: (...t: G) => A ): (...t: G) => IO { - return (...t) => IO.to(C((env, rej, res) => res(fn(...t)))) + return (...t) => IO.from((env, rej, res) => res(fn(...t))) } /** @@ -92,12 +88,11 @@ export class IO implements FIO { fn: (...t: G) => Promise ): (...t: G) => IO { return (...t) => - IO.to( - C((env, rej, res) => { + IO.from( + (env, rej, res) => void fn(...t) .then(res) .catch(rej) - }) ) } @@ -105,7 +100,7 @@ export class IO implements FIO { * Creates an IO that resolves with the provided env */ public static environment(): IO { - return IO.to(C((env1, rej, res) => res(env1))) + return IO.from((env1, rej, res) => res(env1)) } /** @@ -113,7 +108,7 @@ export class IO implements FIO { * In most cases you should use [encase] [encaseP] etc. to create new IOs. * `from` is for more advanced usages and is intended to be used internally. */ - public static from( + public static from( cmp: (env: R, rej: REJ, res: RES) => Cancel | void ): IO { return IO.to(C(cmp)) @@ -123,21 +118,21 @@ export class IO implements FIO { * Creates an [[IO]] that never completes. */ public static never(): IO { - return IO.to(C(RETURN_NOOP)) + return IO.from(RETURN_NOOP) } /** * Creates an [[IO]] that always resolves with the same value. */ public static of(value: A): IO { - return IO.to(C((env, rej, res) => res(value))) + return IO.from((env, rej, res) => res(value)) } /** * Creates an IO that always rejects with an error */ public static reject(error: Error): IO { - return IO.to(C((env, rej) => rej(error))) + return IO.from((env, rej) => rej(error)) } /** @@ -200,7 +195,7 @@ export class IO implements FIO { * Creates an IO that can run in [DefaultEnv]. */ public provide(env: R1): IO { - return IO.to(C((env1, rej, res) => this.io.fork(env, rej, res))) + return IO.from((env1, rej, res) => this.io.fork(env, rej, res)) } /**