Skip to content

Instantly share code, notes, and snippets.

@acdcjunior
acdcjunior / di-via-monads-js-ts.ts
Created June 29, 2019 09:40
Dependency Injection via Monads in JavaScript/TypeScript
import axios, {AxiosInstance} from 'axios';
interface Context {
get(s: string): any;
headersForResource(id: number): any;
}
class Contextual<T> {
constructor(private g: (ctx: Context) => T) {}
run(ctx: Context): T { return this.g(ctx) };