Skip to content

Instantly share code, notes, and snippets.

@orlin
Created December 15, 2010 18:59
Show Gist options
  • Select an option

  • Save orlin/742422 to your computer and use it in GitHub Desktop.

Select an option

Save orlin/742422 to your computer and use it in GitHub Desktop.

Revisions

  1. Orlin M Bozhinov revised this gist Jan 13, 2011. 2 changed files with 49 additions and 18 deletions.
    38 changes: 20 additions & 18 deletions undermix.coffee
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,23 @@
    _ = require("underscore")
    _.mixin require("underscore.strings")
    _.mixin
    define (require, exports, module) ->
    _ = require("underscore")
    _.mixin require("underscore.string")
    _.mixin

    # Converts the arguments list to an Array
    aToArr: (list) ->
    if _.isArguments(list)
    _.toArray(list).slice(0)
    else
    console.log "aToArr called with these non-arguments: #{list}"
    [list]
    # Converts the arguments list to an Array
    aToArr: (list) ->
    if _.isArguments(list)
    _.toArray(list).slice(0)
    else
    console.log "aToArr called with these non-arguments: #{list}"
    [list]

    # Merges all from a list of objects in return for a single one
    # sequentially overwrites keys (with disrespect for nested values)
    allFurther: (into, rest...) ->
    for item in rest
    for key, val of item
    into[key] = val
    into
    # Merges all from a list of objects in return for a single one
    # sequentially overwrites keys (with disrespect for nested values)
    allFurther: (into, rest...) ->
    # _.each rest, (item) -> _.map item, (val, key) -> into[key] = val
    for item in rest
    for key, val of item
    into[key] = val
    into

    module.exports = _
    module.exports = _
    29 changes: 29 additions & 0 deletions undermix.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    var __slice = Array.prototype.slice;
    define(function(require, exports, module) {
    var _;
    _ = require("underscore");
    _.mixin(require("underscore.string"));
    _.mixin({
    aToArr: function(list) {
    if (_.isArguments(list)) {
    return _.toArray(list).slice(0);
    } else {
    console.log("aToArr called with these non-arguments: " + list);
    return [list];
    }
    },
    allFurther: function() {
    var into, item, key, rest, val, _i, _len;
    into = arguments[0], rest = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
    for (_i = 0, _len = rest.length; _i < _len; _i++) {
    item = rest[_i];
    for (key in item) {
    val = item[key];
    into[key] = val;
    }
    }
    return into;
    }
    });
    return module.exports = _;
    });
  2. Orlin M Bozhinov revised this gist Dec 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion undermix.coffee
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ _.mixin

    # Merges all from a list of objects in return for a single one
    # sequentially overwrites keys (with disrespect for nested values)
    oneForAll: (into, rest...) ->
    allFurther: (into, rest...) ->
    for item in rest
    for key, val of item
    into[key] = val
  3. Orlin M Bozhinov revised this gist Dec 15, 2010. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions undermix.coffee
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,18 @@ _ = require("underscore")
    _.mixin require("underscore.strings")
    _.mixin

    # Converts arguments to plain Array
    # Converts the arguments list to an Array
    aToArr: (list) ->
    if _.isArguments(list)
    _.toArray(list).slice(0)[0]
    _.toArray(list).slice(0)
    else
    console.log "aToArr called with these non-arguments: #{list}"
    [list]

    # Merges an array of objects (sequentially overwrites with disrespect for nested values)
    merge: ->
    args = _(arguments).aToArr()
    into = _.first args
    for item in _.rest args
    # Merges all from a list of objects in return for a single one
    # sequentially overwrites keys (with disrespect for nested values)
    oneForAll: (into, rest...) ->
    for item in rest
    for key, val of item
    into[key] = val
    into
  4. Orlin M Bozhinov created this gist Dec 15, 2010.
    22 changes: 22 additions & 0 deletions undermix.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    _ = require("underscore")
    _.mixin require("underscore.strings")
    _.mixin

    # Converts arguments to plain Array
    aToArr: (list) ->
    if _.isArguments(list)
    _.toArray(list).slice(0)[0]
    else
    console.log "aToArr called with these non-arguments: #{list}"
    [list]

    # Merges an array of objects (sequentially overwrites with disrespect for nested values)
    merge: ->
    args = _(arguments).aToArr()
    into = _.first args
    for item in _.rest args
    for key, val of item
    into[key] = val
    into

    module.exports = _