// ets_tracing: off import { succeed } from "./core.js" import type { IO } from "./effect.js" import { effectAsync } from "./effectAsync.js" import { fail } from "./fail.js" export function fromNodeCb( f: (this: unknown, cb: (e: L | null | undefined, r?: R) => void) => void, __trace?: string ): () => IO export function fromNodeCb( f: (this: unknown, a: A, cb: (e: L | null | undefined, r?: R) => void) => void, __trace?: string ): (a: A) => IO export function fromNodeCb( f: (this: unknown, a: A, b: B, cb: (e: L | null | undefined, r?: R) => void) => void, __trace?: string ): (a: A, b: B) => IO export function fromNodeCb( f: ( this: unknown, a: A, b: B, c: C, cb: (e: L | null | undefined, r?: R) => void ) => void, __trace?: string ): (a: A, b: B, c: C) => IO export function fromNodeCb( f: ( this: unknown, a: A, b: B, c: C, d: D, cb: (e: L | null | undefined, r?: R) => void ) => void, __trace?: string ): (a: A, b: B, c: C, d: D) => IO export function fromNodeCb( f: ( this: unknown, a: A, b: B, c: C, d: D, e: E, cb: (e: L | null | undefined, r?: R) => void ) => void, __trace?: string ): (a: A, b: B, c: C, d: D, e: E) => IO export function fromNodeCb( f: (this: unknown, ...args: [...A, (e: L | null | undefined, r?: R) => void]) => void, __trace?: string ): (...args: A) => IO export function fromNodeCb(f: Function, __trace?: string): () => IO { return function () { // eslint-disable-next-line prefer-rest-params const args = Array.prototype.slice.call(arguments) return effectAsync((cb) => { const cbResolver = (e: L, r: R) => (e != null ? cb(fail(e)) : cb(succeed(r))) // eslint-disable-next-line prefer-spread f.apply(null, args.concat(cbResolver)) }, __trace) } }