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 const hasDefinedKey = | |
<K extends PropertyKey>(key: K) => | |
<T extends Partial<Record<K, unknown>>>( | |
obj: T, | |
): obj is T & Record<K, Exclude<T[K], undefined>> => | |
key in obj && obj[key] !== undefined; |
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
(defmacro -> (&rest form) | |
(reduce (lambda (xs x) | |
(if (consp x) | |
(append xs x) | |
(list x xs))) | |
form)) |
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 Tuple<A, B> = [A, B]; | |
function extractErr<E, R>(r: Result<E, R>): E | undefined { | |
return r.type === "error" ? r.value : undefined; | |
} | |
function composeR<E1, E2, R1, R2>( | |
r1: Result<E1, R1>, | |
r2: Result<E2, R2> | |
): Result<Tuple<E1 | undefined, E2 | undefined>, Tuple<R1, R2>> { | |
if (r1.type === "error" || r2.type === "error") | |
return err([extractErr(r1), extractErr(r2)]); |
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
(def tree | |
{:nodes | |
[ | |
{:function "start" | |
:nodes [{:call "end" :nodes [{:call "middle"}]}] | |
} | |
{:function "middle" | |
:nodes [{:call "start"} {:call "end"}]} | |
{:function "end" | |
:nodes [{:call "start"}]} |
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
sub needs-change($o) { $o->name eq 'Seek' } | |
sub change($o) { | |
my %props = %o{qw/name level x y/}; | |
my @perks = @$o->perks; | |
push @perks, $perk_to_add; | |
%props{perks} = \@perks; | |
bless %props, ref($o); | |
} | |
my @updated = map { needs-change($_) ? change($_) : $_ } @objects; |
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
def s [match?: string] { | |
if ($match == null) { | |
git rev-parse --abbrev-ref HEAD | str trim | |
} else { | |
let $branches = git branch | grep -i $match | tr '*' ' ' | lines | str trim | |
let $length = $branches | length | |
if ($length == 0) { | |
"No branch found with hint" | |
} else if ($length == 1) { | |
git checkout $branches.0 |
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
Scorpio "SmallBuff" "0.1" | |
import "System.Reactive" | |
local _Cache = {} | |
local function GetSpellFromCache(id) | |
if not _Cache[id] then | |
local name, _, icon = GetSpellInfo(id) | |
_Cache[id] = { name = name, icon = icon } | |
end |
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 WithKey<T extends object, K extends string> = Record<K, string> & T; | |
class ParseObject<T extends object> { | |
public constructor(private parts: (keyof T)[]) { | |
} | |
public add<K extends string>(k: K): ParseObject<WithKey<T, K>> { | |
const parts: (keyof WithKey<T, K>)[] = [...this.parts, k]; | |
return new ParseObject<WithKey<T, K>>(parts); | |
} |
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
const once = (function () { | |
const fns = []; | |
let i = 0; | |
return function (fn) { | |
const cur = i++; | |
fns[cur] = fn; | |
return function () { | |
if (fns[cur]) { | |
fns[cur].apply(null, arguments); | |
fns[cur] = null; |
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
sealed trait Type {} | |
case class BuiltinType(t: String) extends Type { | |
override def toString = t | |
} | |
case class UnknownType(name: String) extends Type { | |
override def toString = name | |
} | |
case class FunctionType(from: Type, to: Type) extends Type { | |
override def toString: String = { | |
val fromS = from.toString |
NewerOlder