Skip to content

Instantly share code, notes, and snippets.

View UserGalileo's full-sized avatar

Michele Stieven UserGalileo

View GitHub Profile
@UserGalileo
UserGalileo / functions_yielding_monadic_values.js
Created April 14, 2020 17:21
Functions yielding monadic values
// Let's just use the simplest monad, Identity
import { Identity } from 'wherever';
// These are our new elements
const f = x => Identity(x + 1);
const g = x => Identity(x + 2);
const h = x => Identity(x + 3);
@UserGalileo
UserGalileo / functions_monoid.js
Created April 14, 2020 17:15
Functions under composition form a Monoid
// These are our elements
const f = x => x + 1;
const g = x => x + 2;
const h = x => x + 3;
// This is our neutral element, a function which does nothing
const id = x => x;
// This is the composition
f(g(h(1))) // 7
@UserGalileo
UserGalileo / instantiator.module.ts
Last active December 13, 2018 18:41
Angular - InstantiatorModule
import { NgModule, ModuleWithProviders, InjectionToken, Inject, Injector } from '@angular/core';
import { CommonModule } from '@angular/common';
export const INSTANTIATED_SERVICES = new InjectionToken<any[]>('instantiated services');
/**
* This module takes an array of services
* and instantiates them for you. They'll be
* singletons for the injector of the importing module.
*
@UserGalileo
UserGalileo / universal.interceptor.ts
Last active June 15, 2022 13:34
Angular Universal - Interceptor
/**
* This interceptor ensures that the app makes requests
* with relative paths correctly server-side.
* Requests which start with a dot (ex. ./assets/...)
* or relative ones ( ex. /assets/...) will be converted
* to absolute paths
*/
import { Inject, Injectable, Injector, PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';