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
import { describe } from "../utils"; | |
/** | |
* chain (flatmap) | |
* === | |
* the chain can perform `map` and `flatten` together. | |
*/ | |
import { flow, pipe } from "fp-ts/lib/function"; | |
import * as Option from "fp-ts/Option"; |
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
/** | |
* The Flow Operator | |
* === | |
* The `flow` operator is almost same as `pipe` operator. | |
* The difference being the first argument must be a function, rather than value. | |
*/ | |
import { flow, pipe } from "fp-ts/lib/function"; | |
import assert = require("assert"); |
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
/** | |
* The Pipe Operator | |
* === | |
* The basic building block of fp-ts is the Pipe operator. | |
*/ | |
import { pipe } from "fp-ts/lib/function"; | |
type Fn = (a: number) => number; | |
const add1: Fn = (num) => num + 1; |
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
// input: min=2, max=4, value=-1 | |
// return 2 | |
// input: min=2, max=4, value=0 | |
// return 3 | |
// input: min=2, max=4, value=1 | |
// return 4 | |
// input: min=2, max=4, value=2 | |
// return 2 | |
// input: min=2, max=4, value=3 | |
// return 3 |
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
function select(key, el = document) { | |
return el.querySelector(key); | |
} | |
function selectAll(key, el = document) { | |
return Array.from(el.querySelectorAll(key)); | |
} | |
function replace(oldEl, newEl) { | |
oldEl.parentNode.replaceChild(newEl, oldEl); | |
return newEl; | |
} |
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
import { ReactNode, isValidElement, PropsWithChildren } from "react"; | |
type Props<T> = Pick<PropsWithChildren<T>, Exclude<keyof T, "children">>; | |
function isFunction<T, R>(instance: any): instance is (props: T) => R { | |
return typeof instance === "function"; | |
} | |
export default function RenderProps<T>({ | |
children, |
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
export function KeyBoard(keymap) { | |
const pressing = new Set(); | |
window.addEventListener("keydown", ({ key }) => | |
keymap[key] && pressing.add(keymap[key]) | |
); | |
window.addEventListener("keyup", ({ key }) => | |
keymap[key] && pressing.delete(keymap[key]) | |
); |
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
import { Loader } from 'pixi.js'; | |
import { Howl } from 'howler'; | |
const loader = new Loader(); | |
loader.pre(SoundHandler); | |
function SoundHandler(resource, next) { | |
const SUPPORT_FORMATS = ['mp3', 'opus', 'ogg', 'wav', 'aac', 'm4a', 'm4b', 'mp4', 'webm']; |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Simple JSX</title> | |
</head> | |
<body> |
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
/** | |
* Execute a function repeatedly when frame change. | |
* @param {Function} func | |
* @param {any} args | |
* @return {stop} : Function to stop the loop | |
*/ | |
function frameLoop(func, ...args) { | |
let loop = true; | |
(async function execute() { |