Macros and functions are fundamentally trying to achieve the same goal of keeping code DRY. Can this be represented more eloquently?
add $x $y : x + y
$x + $y : add x y
$x plus $y : x + y
(add 10 11) = (10 + 11) = (10 plus 11)
// Objects of interest. | |
var OBJECTS = ['1989', '2102', '1241', '1990', '2084', '889', '891', '1987']; | |
// Gets sessions. | |
var sessions = {} | |
statements.forEach(function (statement) { | |
(sessions[statement.actor.mbox] = sessions[statement.actor.mbox] || []).push(statement) | |
}); | |
// Adds next statement to statement. |
Macros and functions are fundamentally trying to achieve the same goal of keeping code DRY. Can this be represented more eloquently?
add $x $y : x + y
$x + $y : add x y
$x plus $y : x + y
(add 10 11) = (10 + 11) = (10 plus 11)
<?php | |
$isType = function ($type) { | |
return function ($value) use ($type) { | |
return gettype($value) === $type; | |
}; | |
}; | |
$isNum = function ($min = null, $max = null, $numTypes = ['integer', 'double']) { | |
return function ($value) use ($min, $max, $numTypes) { |
type = (fn, params...) -> | |
# Test function. | |
type.validate(fn, params...) | |
# Return type-aware function. | |
(args...) -> | |
# Validate the type of arguments. | |
paramsLen = params[0].length | |
invalidArgs = args.filter((arg, index) -> | |
expectedType = params[0][if index >= paramsLen then paramsLen - 1 else index] |
statements = export; | |
sessions = {} | |
statements.forEach(function (statement) { | |
(sessions[statement.mbox] = sessions[statement.mbox] || []).push(statement.activity) | |
}) | |
activities = {} | |
Object.keys(sessions).forEach(function (session) { | |
var nodes = sessions[session]; |
var Model = function (data) { | |
this._callbacks = {}; | |
this._setProps(data || {}); | |
}; | |
var model = function (data) { | |
return new Model(data); | |
}; | |
// Adds functionality for events. |
var argsArray = function (args) { | |
return Array.prototype.slice.call(args, 0); | |
}; | |
var removeAllChildren = function (element) { | |
var children = argsArray(element.children) | |
children.forEach(element.removeChild.bind(element)); | |
return element; | |
}; |
var Model = function (data) { | |
this._callbacks = {}; | |
this._setProps(data || {}); | |
}; | |
var model = function (data) { | |
return new Model(data); | |
}; | |
// Adds functionality for events. |
var limitText = function (text, options) { | |
// Sets properties to default values if needed. | |
text = text || ''; | |
options = options || {}; | |
options.limit = options.limit || 20; | |
options.moreLink = options.moreLink || '<a href="#more">Read more</a>'; | |
options.close = options.close || /<\/(\w+)>/g;; | |
// Limits text. | |
var less = text.slice(0, options.limit); |