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
const scope = callback => ({ | |
with: Function(`with(arguments[0])return(${callback})()`) | |
}); | |
scope(() => ['a', test, 'c']).with({test: 'b'}); | |
// ["a", "b", "c"] |
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 Control.Applicative | |
import Data.Char | |
newtype Parser a = P (String -> [(a, String)]) | |
parse :: Parser a -> String -> [(a, String)] | |
parse (P p) s = p s | |
instance Functor Parser where |
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
function bind(ambient, name, value) { | |
return function lookup(n) { | |
if(n == name) { | |
return value | |
} else { | |
return ambient(n) | |
} | |
} | |
} |
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
function isObject(entity) { | |
return typeof entity === "object" && entity !== null; | |
} | |
function cloneNonObjectProperties(obj) { | |
return Object.fromEntries( | |
Object.entries(obj).filter(([, v]) => !isObject(v)) | |
) | |
} |
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
data Expr = Val Int | Add Expr Expr | Mul Expr Expr deriving (Show) | |
data Op = EVALA Expr | ADD Int | EVALM Expr | MUL Int | |
type Cont = [Op] | |
eval :: Expr -> Cont -> Int | |
eval (Val n) c = exec c n | |
eval (Add e f) c = eval e (EVALA f : c) | |
eval (Mul e f) c = eval e (EVALM f : c) |
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
const IO = (function(io) { | |
io.return = x => () => x; | |
io.unit = io.return; | |
io.of = io.return; | |
io.bind = a => fa => () => fa(a())(); | |
io.flatten = aa => io.bind(aa)(a => io.bind(a)(ar => io.return(ar))); | |
io.join = io.flatten | |
io.takeLeft = a => b => io.bind(a)(ar => io.bind(b)(_ => io.return(ar))); | |
io.takeRight = a => b => io.bind(a)(_ => 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
const Point = (x = 0, y = 0) => ({ | |
setCartesianCoordinates(_x, _y) { | |
x = _x; y = _y; | |
}, | |
setPolarCoordinates(radius, angle) { | |
x = radius * Math.cos(angle); | |
y = radius * Math.sin(angle); | |
}, | |
getCartesianCoordinates() { | |
return { x, y } |
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 interface Message { | |
status: string; | |
query: string; | |
step: string; | |
richResponse: boolean; | |
payload: Types extends (any) ? Payload<Types> : never; | |
sessionId?: number; | |
} | |
type Types = 'text' | 'date' | 'articles' | 'params'; |
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
// https://gal.hagever.com/posts/typing-the-technical-interview-in-typescript/ | |
type Eq<A, B extends A> = "passes"; // B <= A | |
// type test_eq = [ | |
// Eq<"Hello", "Hello">, // passes | |
// Eq<"Hello", "world"> // fails with "'world' does not satisfy constraint 'Hello'" | |
// ]; | |
type NAN = "invalid number"; // we don't support negative numbers |
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
type ActionsTypesExample = "INIT" | "SYNC" | "LOG_IN" | "LOG_IN_SUCCESS" | "LOG_OUT" | |
type SafeKeyValueMapExample<KS extends keyof any> = { | |
readonly [K in KS]: K; | |
}; | |
const ACTIONS_TYPES_MAP_EXAMPLE: SafeKeyValueMapExample<ActionsTypesExample> = { | |
INIT: "INIT", | |
SYNC: "SYNC", | |
LOG_IN: "LOG_IN", |