Skip to content

Instantly share code, notes, and snippets.

(defmacro -> (&rest form)
(reduce (lambda (xs x)
(if (consp x)
(append xs x)
(list x xs)))
form))
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)]);
(def tree
{:nodes
[
{:function "start"
:nodes [{:call "end" :nodes [{:call "middle"}]}]
}
{:function "middle"
:nodes [{:call "start"} {:call "end"}]}
{:function "end"
:nodes [{:call "start"}]}
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;
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
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
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);
}
@vendethiel
vendethiel / once.js
Last active March 31, 2022 12:18
Once
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;
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
import Control.Monad
import Control.Monad.State
import Data.Sequence as Seq
import Data.Foldable (toList)
import Debug.Trace
import Data.Maybe
import Text.Printf
data Direction = East | South | West | North
nextDirection :: Direction -> Direction