Abstracted version of http://stackoverflow.com/a/18937118. Note: this _does not work_ with nested set
483750
function nestedApply(obj, path, fun) {
	if (path.length === 0) {
		const _ret = fun(obj);
		return {
			ret: _ret,
			newObj: obj
		};
	}
	// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
	let newObj = obj;
	const last = path.pop();
	for (const elem of path) {
		if (!newObj[elem])
			newObj[elem] = {};
		newObj = newObj[elem];
	}
	const ret = fun(newObj[last]);
	return {
		ret,
		newObj
	};
}
125561
function Set(a,_sorted) {
  if (a._Set) return a;
  if (!_sorted) a=sortUnique(a);

  //@returns Boolean. Detect if x is in set.
  //`cmp` is custom compare functions return -1,0,1.
  // function cmp(x,item):Ordering(LT=-1|EQ=0|GT=1);
  a.contains=function (x,cmp) {return !!~bsearch(a,x,cmp)};
  a.indexOf=function (x,cmp) {return bsearch(a,x,cmp)};
  a.toArray=function () {return copyArray(a);};

  /** Union with another Set
  @param {Set|Array} b If b is an array,it will be corrupted by sortUnqiue
  @return {Set} return new Set */
  a.union=function (b) {
    b=Set(b);
    var n=a.length+b.length,c=new a.constructor(n);
    for (var i=0,j=0,k=0;k<n;k++) {//merge
      if (a[i]===b[j]) {c[k]=a[i++];j++;n--;}
      else if (a[i]<b[j]) c[k]=a[i++];
      else c[k]=b[j++];
    }
    c.length=n;
    return Set(c.length===n?c:copyArray(c,n),true);
  };

  a.inspect=a.toArray;
  a._Set=true;
  return a;
}
217020
def recalculate_nested_set(left) #:nodoc:
      child_left = left + 1
      children.each do |child|
        child_left = child.recalculate_nested_set(child_left)
      end
      set_boundaries(left, child_left)
      save_without_validation!
      
      right + 1
    end
1186522
function set(i, item, array)
{
	if (i < 0 || length(array) <= i)
	{
		return array;
	}
	return unsafeSet(i, item, array);
}
1146048
function createSubset(keywords, doc) {

    if (!keywords || Object.prototype.toString.call(keywords) !== '[object Array]') {
      return doc;
    }

    var lookup = createLookUp(keywords);

    return traverseThroughObject(lookup, doc);

  }
1192425
def generic_set(key, value, tree = data)
      modify(key, value, tree) || uncomment(key, value, tree) ||
        add_new(key, value, tree)
    end
808887
def nested_join(array, o_str= '{', c_str= '}'):
    '''
        
    '''
    result = ''
    for x in array :
        if type(x) == type([])  :
            result  +=o_str+ nested_join(x)+ c_str
        else                    :
            result  +=x
    return result
60676
function createSet(values) {
    var set = new Set();
    Lazy(values || []).flatten().each(function(e) {
      set.add(e);
    });
    return set;
  }
617714
def _add_child(self, collection, set, child):
        """"""
        added = None
        for c in child:
            if c not in set:
                set.add(c)
                collection.append(c)
                added = 1
        if added:
            self._children_reset()
1148445
private static void validateSetValueEntryForSet(Object entry, Set<?> set) {
    if (entry instanceof Set<?> || entry instanceof SetValue) {
      throw new IllegalArgumentException("Unsupported Value type [nested sets]");
    }
    if (!set.isEmpty()) {
      Object existingEntry = set.iterator().next();
      if (!existingEntry.getClass().isAssignableFrom(entry.getClass())) {
        throw new IllegalArgumentException(
            String.format(
                "Unsupported Value type [SetValue with " + "mixed types %s and %s]",
                existingEntry.getClass(), entry.getClass()));
      }
    }
  }
859866
def combine_sets(*sets):
    
    combined = set()
    for s in sets:
        combined.update(s)
    return combined
522117
function(setA, setB, property1, property2){
	// p for param
	// v for value
	var numProps = numericProperties(setA, setB, property1, property2);
	var sAv1 = numProps.sAv1,
		sAv2 = numProps.sAv2,
		sBv1 = numProps.sBv1,
		sBv2 = numProps.sBv2,
		count = sAv2 - sAv1 + 1;

	var after = {
		difference: [sBv2+1, sAv2],
		intersection: [sAv1,sBv2],
		union: [sBv1, sAv2],
		count: count,
		meta: "after"
	};
	var before = {
		difference: [sAv1, sBv1-1],
		intersection: [sBv1,sAv2],
		union: [sAv1, sBv2],
		count: count,
		meta: "before"
	};

	// if the sets are equal
	if(sAv1 === sBv1 && sAv2 === sBv2) {
		return {
			intersection: [sAv1,sAv2],
			union: [sAv1,sAv2],
			count: count,
			meta: "equal"
		};
	}
	// A starts at B but A ends later
	else if( sAv1 === sBv1 && sBv2 < sAv2 ) {
		return after;
	}
	// A end at B but A starts earlier
	else if( sAv2 === sBv2 && sBv1 > sAv1 ) {
		return before;
	}
	// B contains A
	else if( within(sAv1, [sBv1, sBv2]) && within(sAv2, [sBv1, sBv2]) ) {
		return {
			intersection: [sAv1,sAv2],
			union: [sBv1, sBv2],
			count: count,
			meta: "subset"
		};
	}
	// A contains B
	else if( within(sBv1, [sAv1, sAv2]) && within(sBv2, [sAv1, sAv2]) ) {
		return {
			intersection: [sBv1,sBv2],
			// there is a difference in what A has
			difference: [null, null],
			union: [sAv1, sAv2],
			count: count,
			meta: "superset"
		};
	}
	// setA starts earlier and overlaps setB
	else if(sAv1 < sBv1 && within(sAv2, [sBv1, sBv2]) ) {
		return before;
	}
	// setB starts earlier and overlaps setA
	else if(sBv1 < sAv1 && within(sBv2, [sAv1, sAv2]) ) {
		return after;
	}
	// side by side ... nothing intersection
	else if(sAv2 === sBv1-1) {
		return {
			difference: [sAv1,sAv2],
			union: [sAv1, sBv2],
			count: count,
			meta: "disjoint-before"
		};
	}

	else if(sBv2 === sAv1 - 1) {
		return {
			difference: [sAv1,sAv2],
			union: [sBv1, sAv2],
			count: count,
			meta: "disjoint-after"
		};
	}
	if(!isNaN(count)) {
		return {
			count: count,
			meta: "disjoint"
		};
	}

}
1020219
function arrayContainsArray(superset, subset, some) {
  if (Array.isArray(superset) !== true) { throw new Error(`[ethjs-util] method arrayContainsArray requires input 'superset' to be an array got type '${typeof superset}'`); }
  if (Array.isArray(subset) !== true) { throw new Error(`[ethjs-util] method arrayContainsArray requires input 'subset' to be an array got type '${typeof subset}'`); }

  return subset[Boolean(some) && 'some' || 'every']((value) => (superset.indexOf(value) >= 0));
}
9611
def within_set(df, items=None):
    
    for k, v in items.items():
        if not df[k].isin(v).all():
            raise AssertionError
    return df
748866
function newNestedIndex(vectors) {
  var arity = vectors.length;
  if (arity === 0) {
    throw new Error('cannot index an empty list of vectors');
  }
  var numRows = vectors[0].size();

  // Initialize properties
  var nestedIndex = Object.create(nestedIndexProto);
  nestedIndex.initVectors = vectors;
  nestedIndex.size = 0;
  nestedIndex.arity = arity;
  nestedIndex._dtypes = vectors.map(function(v) { return v.dtype; });
  nestedIndex._map = Object.create(null);

  // Build index
  var rootMap = nestedIndex._map;
  var lastColInd = arity - 1;
  for (var i = 0; i < numRows; i++) {
    var currMap = rootMap;
    var currVector, key;
    for (var j = 0; j < lastColInd; j++) {
      currVector = vectors[j];
      key = cleanKey(currVector.values[i], currVector.dtype);
      var innerMap = currMap[key];

      // Create innerMap if not present
      if (isUndefined(innerMap)) {
        currMap[key] = innerMap = Object.create(null);
      }
      currMap = innerMap;
    }

    // Add the row number to the entry
    currVector = vectors[lastColInd];
    key = cleanKey(currVector.values[i], currVector.dtype);
    var rowNums = currMap[key];
    if (isUndefined(rowNums)) {
      currMap[key] = i;
      nestedIndex.size++;
    } else if (typeof rowNums === 'number') {
      currMap[key] = [rowNums, i];
    } else {
      // rowNums must be an array
      rowNums.push(i);
    }
  }

  return nestedIndex;
}
976846
def nested_map(x, f):
  """"""
  if isinstance(x, list):
    return [nested_map(y, f) for y in x]
  if isinstance(x, tuple):
    return tuple([nested_map(y, f) for y in x])
  if isinstance(x, dict):
    return {k: nested_map(x[k], f) for k in x}
  return f(x)
1174216
def _maybe_nest_bare_single(items_by_key, parallel):
    
    if (parallel == "multi-parallel" and
          (sum([1 for x in items_by_key.values() if not _is_nested_item(x)]) >=
           sum([1 for x in items_by_key.values() if _is_nested_item(x)]))):
        out = {}
        for k, v in items_by_key.items():
            out[k] = [v]
        return out
    else:
        return items_by_key