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
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Effect.Class (liftEffect) | |
import Effect.Aff (Aff, launchAff_) | |
import Node.FS.Aff as FS | |
import Node.Buffer as Buffer | |
import Node.Encoding (Encoding(..)) |
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
// brand.ts | |
// use symbol, but don't export it! | |
declare const _brand: unique symbol; | |
export type Brand<Name, Type> = Type & { [_brand]?: Name } | |
// degree-module.ts | |
export type Celcius = Brand<'Celcius', number>; | |
export type Fahrenheit = Brand<'Fahrenheit', 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
// Counter.jsx | |
import * as React from 'react' | |
import { useCounterReducer } from './useCounterReducer' | |
const Counter = () => { | |
const [[counter, effect], actions] = useCounterReducer(); | |
// Hooks ini hanya berfokus pada "side-effect" dari reducer di atas | |
React.useEffect(() => { | |
if (effect === 'INVALID_STATE') { |
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
// useCounterReducer.js | |
import * as React from 'react'; | |
// Array destructuring disini sangat membantu code readability | |
const counterReducer = ([state, effect], action) => { | |
if (action.type === 'INCREMENT') { | |
return [state + 1]; | |
} | |
if (action.type === 'DECREMENT') { |
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 Counter = () => { | |
// ... | |
const decr = () => { | |
if (state === 0) { | |
alert('Ya akhi, nilai counter ndak boleh di bawah 0 😚'); | |
} else { | |
dispatch('DECREMENT'); |
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
// Counter.jsx | |
import * as React from 'react' | |
import { useCounterReducer } from './useCounterReducer' | |
const Counter = () => { | |
const [counter, dispatch] = useCounterReducer(); | |
React.useEffect(() => { | |
if (counter < 0) { | |
alert('Ya akhi, nilai counter ndak boleh di bawah 0 😚'); |
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
// useCounterReducer.js | |
import * as React from 'react'; | |
const counterReducer = (state, action) => { | |
if (action.type === 'INCREMENT') { | |
return state + 1; | |
} | |
if (action.type === 'DECREMENT') { | |
return state - 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
const map = <F, A, B>(fn: (val: A) => B, thing: F<A>): F<B> = /* IMPL */; |
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 Tree<A> = Leaf<A> | Branch<A> | |
type Leaf<A> = { | |
kind: 'leaf'; | |
value: A; | |
} | |
type Branch<A> = { | |
kind: 'branch'; | |
left: Tree<A>; | |
right: Tree<A>; | |
} |
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
interface Array<T> { | |
map: ... | |
filter: ... | |
reduce: ... | |
length: number; | |
... | |
} | |
const names: Array<string> = ['jihad', 'waspada'] | |
const odds: Array<number> = [1, 3, 5, 7] | |
// etc |
NewerOlder