(Hask)
f
Maybe Int ---> Int
| |
fmap a | | a
v g v
Maybe Bool --> Bool
| |
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 x: { x: number } | null = { x: 10 } | |
console.log(x.x) // no errors | |
const y: { x: number } | null = null | |
console.log(y.x) // 2531: Object is possibly 'null'. |
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
/** | |
* The type 'true' means a proof is satisfied. | |
* The type 'never' means a proof is not satisfied. | |
*/ | |
// Basic of this idea. | |
type AWrongProof = { x: number } extends { x: string } ? true : never | |
// Compile NG |
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
/** | |
* Proves that A and B is the same types. | |
*/ | |
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never | |
/** | |
* Makes all fields of A to `<its-type> | null`. | |
*/ | |
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null } |
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
/** | |
* Proves that A and B is the same types. | |
*/ | |
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never | |
/** | |
* Makes all fields of A to `<its-type> | null`. | |
*/ | |
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null } |
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 axios from 'axios' | |
function isThatArray<T>(x: unknown, p: (a: unknown) => a is T): x is Array<T> { | |
return Array.isArray(x) && x.every(p) | |
} | |
function isString(x: unknown): x is string { | |
return typeof x === 'string' | |
} |
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
{-# LANGUAGE TypeSynonymInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
newtype Fix f = Fix | |
{ unFix :: f (Fix f) | |
} | |
cata :: Functor f => (f a -> a) -> Fix f -> a | |
cata f (Fix x) = f $ fmap (cata f) x |
(Hask)
f
Maybe Int ---> Int
| |
fmap a | | a
v g v
Maybe Bool --> Bool
| |
(Hask)
f
Maybe Int ---> Int
| |
fmap a | | a
v g v
Maybe Bool --> Bool
| |
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
#!/bin/bash | |
# もし現在のgitブランチ(ここでfooとします。)がpushされていれば、{remote_name}/fooを返します。 | |
# そうでなければこのブランチのルートとなるブランチ(分岐元)を取得し、それを返します。 | |
# | |
# このプログラムはまず、リモート名を取得します。 | |
# remoteが複数登録されている場合の適切な処理は未定義です。 | |
# 現在は1番目のリモートを使用するようになっています。 | |
# Returns tags and branches names of the root revision of current. |