Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active September 13, 2016 10:15
Show Gist options
  • Save cobalamin/b9f02ed9d7643045d855705835bac15a to your computer and use it in GitHub Desktop.
Save cobalamin/b9f02ed9d7643045d855705835bac15a to your computer and use it in GitHub Desktop.
range : number -> number -> List number
range s e =
if s < e then
rangeWith (-) (<) e s []
else
rangeWith (+) (>) e s []
rangeWith : (number -> number -> number) -> (number -> number -> Bool) -> number -> number -> List number -> List number
rangeWith modifyCount compare s e acc =
if compare s e then
acc
else
rangeWith modifyCount compare (modifyCount s 1) e (s :: acc)
var _user$project$Range$rangeWith = F5(
function (modifyCount, compare, s, e, acc) {
rangeWith:
while (true) { // this is tail-recursive optimisation
if (A2(compare, s, e)) {
return acc;
} else {
var _v0 = modifyCount,
_v1 = compare,
_v2 = A2(modifyCount, s, 1),
_v3 = e,
_v4 = A2(_elm_lang$core$List_ops['::'], s, acc);
modifyCount = _v0;
compare = _v1;
s = _v2;
e = _v3;
acc = _v4;
continue rangeWith;
}
}
});
var _user$project$Range$range = F2(
function (s, e) {
return (_elm_lang$core$Native_Utils.cmp(s, e) < 0) ? A5(
_user$project$Range$rangeWith,
F2(
function (x, y) {
return x - y;
}),
F2(
function (x, y) {
return _elm_lang$core$Native_Utils.cmp(x, y) < 0;
}),
e,
s,
_elm_lang$core$Native_List.fromArray(
[])) : A5(
_user$project$Range$rangeWith,
F2(
function (x, y) {
return x + y;
}),
F2(
function (x, y) {
return _elm_lang$core$Native_Utils.cmp(x, y) > 0;
}),
e,
s,
_elm_lang$core$Native_List.fromArray(
[]));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment