This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type If<T, U, True, False> = [T] extends [U] ? True : False; | |
export type IfDef<T, Yep, Nope> = If<T, never, Nope, Yep>; | |
export type Intersect<A extends {}, B extends {}> = | |
Pick<A, Exclude<keyof A, Exclude<keyof A, keyof B>>> extends { [x: string]: never } ? | |
never : | |
Pick<A, Exclude<keyof A, Exclude<keyof A, keyof B>>>; | |
const f = < | |
A extends {}, | |
B extends {}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { log } from 'fp-ts/lib/Console'; | |
import { Type, URIS } from 'fp-ts/lib/HKT'; | |
import { identity, URI as IdURI } from 'fp-ts/lib/Identity'; | |
import { none, Option, some } from 'fp-ts/lib/Option'; | |
import { randomInt } from 'fp-ts/lib/Random'; | |
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task'; | |
import { createInterface } from 'readline'; | |
export interface ProgramSyntax<F extends URIS, A> { | |
map: <B>(f: (a: A) => B) => _<F, B>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AbortController from 'abort-controller'; | |
import { circuitBreaker, defaultBreakerOptions } from 'circuit-breaker-monad/lib'; | |
import { BreakerClosed, BreakerOpen, BreakerState } from 'circuit-breaker-monad/lib/types'; | |
import { Either, left } from 'fp-ts/lib/Either'; | |
import { Lazy } from 'fp-ts/lib/function'; | |
import { IORef } from 'fp-ts/lib/IORef'; | |
import fetch from 'node-fetch'; | |
const fetcher = circuitBreaker<User[]>().run(defaultBreakerOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { identity, Identity } from 'fp-ts/lib/Identity'; | |
import { io, IO } from 'fp-ts/lib/IO'; | |
import { doM } from './syntax'; | |
describe('Monad do-syntax', () => { | |
beforeAll(() => { | |
jest.spyOn(Identity.prototype, 'chain'); | |
jest.spyOn(IO.prototype, 'chain'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.higherKinds | |
import cats._ | |
import cats.implicits._ | |
final case class User(id: Integer, name: String, age: Integer, isAdmin: Boolean) | |
val fakeUsers: List[User] = List( | |
User(1, "John Connor", 32, false), | |
User(2, "John Smith", 18, false), | |
User(3, "Mark Brian", 28, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HKT, Type, URIS } from 'fp-ts/lib/HKT'; | |
import { identity, Identity, URI } from 'fp-ts/lib/Identity'; | |
import { Monad, Monad1 } from 'fp-ts/lib/Monad'; | |
// Task: get all users named 'John' and make them admins | |
interface User { | |
id: number; | |
name: string; | |
age: number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { foldFree, liftF } from 'fp-ts/lib/Free'; | |
import { identity, Identity } from 'fp-ts/lib/Identity'; | |
// Task: get all users named 'John' and make them admins | |
interface User { | |
id: number; | |
name: string; | |
age: number; | |
isAdmin: boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `fix` is an Y-combinator implementation (recursive calls in lambda calculus): | |
// Y = \f -> (\x -> f (x x))(\x -> f (x x)) | |
// fix :: (a -> a) -> a | |
const fix = f => (x => f(y => (x(x))(y)))(x => f(y => (x(x))(y))); | |
// Generator function. Inner signature should correspond to actual function interface. | |
// mapgen :: ((a -> b) -> [a] -> [b]) -> (a -> b) -> [a] -> [b] | |
const mapgen = map => f => list => list.length === 0 ? [] : [f(list[0]), ...map(f)(list.slice(1))]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Set build action 'Embedded Resourse'. | |
// 2. Run this handler as early as possible: | |
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => | |
{ | |
string resourceName = "Your.Assembly.Name.Here." + new AssemblyName(args.Name).Name + ".dll"; | |
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) | |
{ | |
if (stream == null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Windows\System32\Inetsrv\appcmd.exe set site /site.name: %1 /+bindings.[protocol='http',bindingInformation='*:80:%2'] |
NewerOlder