The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.
Send messages to iframe using iframeEl.contentWindow.postMessage
Recieve messages using window.addEventListener('message')
type ParamParser<T extends string> = T extends `${infer param}/${infer rest}` ? [param, ...ParamParser<rest>] : [T] | |
type TakeApart<T extends string> = T extends `${infer p}=${infer v}` ? [p, v] : [] | |
type QueryParser<T extends string> = T extends `${infer el}&${infer rest}` ? [TakeApart<el>, ...QueryParser<rest>]: [TakeApart<T>] | |
type urlWithParamAndQuery<T extends string, FB = never> = T extends `${infer Base}/${infer Param}?${infer Query}` ? {base: Base, param: ParamParser<Param>, query: QueryParser<Query>} : FB; | |
type urlWithQuery<T extends string, FB = never> = T extends `${infer Base}?${infer Query}` ? {base: Base, param: [], query: QueryParser<Query>} : FB; | |
type urlWithParam<T extends string, FB = never> = T extends `${infer Base}/${infer Param}` ? {base: Base, param: ParamParser<Param>, query: []} : FB; | |
type staticUrl<T extends string> = {base: T, param: [], query: []}; | |
type url<T extends string> = urlWithParamAndQuery<T, urlWithParam<T, urlWithQuery<T, staticUrl<T>>>>; |
package main | |
import ( | |
"errors" | |
"fmt" | |
) | |
type RS[R any] struct { | |
a R | |
err error |
type SortedArray<T> = Array<T> & {readonly _tag: "SortedArray ${T}"}; | |
type VersionA<T extends string> = T extends `${infer major}.${infer minor}.${infer patch}` ? T : never; | |
type ComparisionRes = 'LT' | 'EQ' | 'GT'; | |
class Version<T extends string> { | |
readonly major: T extends `${infer major}.${infer minor}.${infer patch}` ? major : never; | |
private readonly majorN: number; | |
readonly minor: T extends `${infer major}.${infer minor}.${infer patch}` ? minor : never; |
Video Tutor | |
Login Module | |
Unauthorized Dashboard | |
existing user -> SignIn | |
new user -> SignUp | |
SignUp | |
already an user -> SignIn | |
submit info -> SubscribeUser | |
SubscribeUser | |
user pick a plan -> 2checkoutSubscribtion |
// Proper try data structure implementation in typescript | |
// pass as thunk | |
type $<A> = () => A | |
function $<A>(a: A): $<A>{ | |
return () => a | |
} | |
// make function lazy | |
function $fn<A extends (...args: any) => any>(a: A): ((...p: Parameters<A>) => $<ReturnType<A>>) { |
Lets define a sum type `Ordering` with its data constructors: | |
```typescript | |
class LT {} | |
class EQ {} | |
class GT {} | |
type Ordering = LT | EQ | GT; | |
class Comparison<A> { |
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.
val square : Int => Int = x => x * x
abstract class Season { | |
cata<W, Su, Sp, Au>(match: { | |
Winter: () => W, | |
Summer: () => Su, | |
Autumn: () => Au, | |
Spring: () => Sp | |
}) { | |
type constraintsT = keyof typeof match; | |
switch (this.constructor.name as unknown as constraintsT) { | |
case 'Winter': { |
// Universal constructions based on Bartosz Milewski talk on Scala World | |
// type ProductT<C, A, B> = | |
function fanout<C, A, B>(f: (c: C) => A, g: (c: C) => B): ((c: C) => [A, B]) { | |
return c => [f(c), g(c)] | |
} | |
// const x = fanout((a: number) => a + 1, b => b + 2)(4) |