** [] https://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
This file contains hidden or 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
// 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) |
This file contains hidden or 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
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': { |
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
This file contains hidden or 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
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> { |
This file contains hidden or 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
// 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>>) { |
This file contains hidden or 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
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 |
This file contains hidden or 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 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; |
This file contains hidden or 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
package main | |
import ( | |
"errors" | |
"fmt" | |
) | |
type RS[R any] struct { | |
a R | |
err error |