Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
Bug hunting 🎯

Simon Richardson SimonRichardson

👻
Bug hunting 🎯
View GitHub Profile
var Option = require('fantasy-options')
var Some = Option.Some;
var None = Option.None;
var Compose = function(x){
this.val = x;
}
Compose.prototype.map = function(f){
return new Compose(this.val.map(function(u){return u.map(f); }));
import scalaz._
// A right Kan extension of `F` along itself, constrained by `C`.
trait RCodensity[C[_], F[_], A] {
def apply[R:C](k: A => F[R]): F[R]
}
object RCodensity {
implicit def codensityMonad[C[_], F[_]]: Monad[({type f[x] = RCodensity[C,F,x]})#f] =
new Monad[({type f[x] = RCodensity[C,F,x]})#f] {
@levjj
levjj / sweet-units.sjs
Last active August 29, 2015 13:56
Units of measure with sweet.js
// Some minimal class for values with units
// (nothing exciting going on...)
function Unit(name,val) {
this.name = name;
this.val = val;
}
Unit.prototype.toString = function() {
return this.val + " " + this.name;
}
@dpeek
dpeek / VerEx.hx
Last active May 3, 2019 19:38
VerbalExpressions for Haxe
class VerEx
{
public static function main()
{
var test = new VerEx()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
@disnet
disnet / gist:6024991
Created July 17, 2013 22:09
cond macro
macro _arms {
case (default => $value:expr) => {
else {
return $value;
}
}
case (case $cond:expr => $value:expr) => {
if($cond) {
return $value;
}
@puffnfresh
puffnfresh / index.js
Created July 8, 2013 18:19
made with requirebin.com
var State = require('fantasy-states'),
Tuple2 = require('fantasy-tuples').Tuple2,
// Tuple2 Number Number
initial = Tuple2(0, 1),
// State (Tuple2 Number Number) Number -> State (Tuple2 Number Number) Number
next = discard(
State.modify(function(t) {
return Tuple2(t._1 + 1, (t._1 + 1) * t._2);
@Simn
Simn / Main.hx
Created May 7, 2013 18:49
printf for haxe using GADT and macros
class Main {
static public function main () {
var v = Printf.sprintf("The sum of $i and $i is $s.", 3, 5, "8");
trace(v); // The sum of 3 and 5 is 8.
}
}
@puffnfresh
puffnfresh / Example.hx
Last active March 6, 2020 01:09
Macro to generate "value classes" in Haxe
import precog.macro.ValueClass;
class ABC implements ValueClass {
var a: Int;
var b: Bool;
var c: String;
}
/*
class ABC extends ValueClass {
@Simn
Simn / AbstractBuilder.hx
Created February 22, 2013 07:48
Haxe abstract builder example
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
class AbstractBuilder {
macro static public function build():Array<Field> {
var fields = Context.getBuildFields();
var cCur = Context.getLocalClass().get();
var fieldMap = [for (f in fields) f.name => true];
function loop(c:ClassType) {
@andyli
andyli / AbstractClass.hx
Last active June 24, 2021 13:40
Java abstract class implemented in Haxe macros. Related: https://groups.google.com/forum/?fromgroups=#!topic/haxelang/WzeI-N1XbIg
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using Lambda;
/**
Old school abstract class.
Classes that implements it, and their sub-classes, will be able to declare abstract methods (methods that without body).
There will be a check in compile-time such that no public constructor is allowed without all abstract methods implemented.
*/