Last active
August 29, 2015 14:03
-
-
Save kl0tl/0de194392ac88691a732 to your computer and use it in GitHub Desktop.
Inline `Array#every`
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
macro inline_every { | |
rule { ($list:expr, function ($value:ident, $index:ident, $ref:ident) { | |
$return:expr | |
}, $context:expr) } => { | |
(function ($ref) { | |
var length = $ref.length; | |
for (var $index = 0; $index < length; $index += 1) { | |
var $value = $ref[$index]; | |
if (!$return) return false; | |
} | |
return true; | |
}.call($context, $list)) | |
} | |
} | |
let every = macro { | |
rule infix { $list:expr . | (() => $return:expr) } => { | |
inline_every($list, function (value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (() => $return:expr, $context:expr) } => { | |
inline_every($list, function (value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | ($value:ident => $return:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | ($value:ident => $return:expr, $context:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident) => $return:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident) => $return:expr, $context:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident) => $return:expr) } => { | |
inline_every($list, function ($value, $index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident) => $return:expr, $context:expr) } => { | |
inline_every($list, function ($value, $index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident, $ref:ident) => $return:expr) } => { | |
inline_every($list, function ($value, $index, $ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident, $ref:ident) => $return:expr, $context:expr) } => { | |
inline_every($list, function ($value, $index, $ref) { $return }, this) | |
} | |
rule { $rest ... } => { find $rest ... } | |
} | |
export every; | |
let every = macro { | |
rule infix { $list:expr . | (() => $return:expr) } => { | |
inline_every($list, function (value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | ($value:ident => $return:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident) => $return:expr) } => { | |
inline_every($list, function ($value, index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident) => $return:expr) } => { | |
inline_every($list, function ($value, $index, ref) { $return }, this) | |
} | |
rule infix { $list:expr . | (($value:ident, $index:ident, $ref:ident) => $return:expr) } => { | |
inline_every($list, function ($value, $index, $ref) { $return }, this) | |
} | |
rule { $rest ... } => { every $rest ... } | |
} | |
export every; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment