Alias: collect

@chainable
@category  Collections
@param     array     $xs
@param     callable  $f
@return    Generator
196788
public static function map($xs, $f)
    {
        foreach ($xs as $i => $x) {
            yield $i => call_user_func($f, $x, $i, $xs);
        }
    }
555335
public static function reduce(callable $f, $xs, $initial = null)
    {
        if (is_array($xs)) {
            $initial = $initial !== null ? $initial : array_shift($xs);
            return array_reduce($xs, $f, $initial);
        }
        if ($xs instanceof \Iterator) {
            $xs->rewind();
            if (!$xs->valid()) {
                return $initial;
            }
            $acc = $initial;
            if ($acc === null) {
                $acc = $xs->current();
                $xs->next();
            }
            for (; $xs->valid(); $xs->next()) {
                $acc = call_user_func($f, $acc, $xs->current());
            }
            return $acc;
        }
        throw new \InvalidArgumentException();
    }
923511
public function unique(callable $func = null)
    {
        return new Enumerator(
            function () use ($func) {
                $exists = [];
                foreach ($this->each() as $k => $v) {
                    $comp = $func ? $func($v) : $v;
                    if (!in_array($comp, $exists, true)) {
                        $exists[] = $comp;
                        yield $k => $v;
                    }
                }
            }
        );
    }
1200121
private function getOrCreateRoot($namespace, $title, $locale, $userId, $parent = null)
    {
        if (null !== ($collection = $this->collectionManager->getByKey($namespace, $locale))) {
            $collection->setTitle($title);

            return $collection;
        }

        return $this->createCollection($title, $namespace, $locale, $userId, $parent);
    }
650777
public function except($keys): CollectionInterface
    {
        if (!is_callable($keys)) {
            if (!is_array($keys)) {
                $keys = func_get_args();
            }
            $keys = function ($item, $key) use ($keys) {
                return in_array($key, $keys, false);
            };
        }

        return $this->wrap(function (Iterator $data) use ($keys) {
            foreach ($data as $key => $item) {
                if (!$keys($item, $key)) {
                    yield $key => $item;
                }
            }
        });
    }
876041
static function instance(\hlin\archetype\Filesystem $fs, array $filemaps) {
		$i = new static;
		$i->fs = $fs;
		$i->filemaps = $filemaps;
		return $i;
	}
277994
public static function unfold(callable $f, $seed): Tree
    {
        $unfold = function (callable $f) use (&$unfold): Closure {
            return function ($seed) use (&$unfold, $f): Tree {
                [$node, $remaining] = $f($seed);
                return new Tree($node, \array_map($unfold($f), $remaining));
            };
        };
        [$node, $remaining] = $f($seed);
        return new Tree($node, \array_map($unfold($f), $remaining));
    }
930293
function (oTree, sSeparator) {
			var oObject = this.toHierarchy(oTree),
				aFilters = [];

			function collect(sName, oObject) {
				var aChildren, bChildren;
				if (typeof oObject === 'object') {
					if (oObject['']) {
						aFilters.push(sName + '/');
						return;
					}
					aChildren = Object.keys(oObject);
					bChildren = aChildren.length;
				}
				if (bChildren) {
					aChildren.forEach(function (sChild) {
						if (sChild === '') {
							return;
						}
						if (oObject[sChild] === true) {
							aFilters.push((sName ? sName + '/' : '') + sChild);
						} else if (typeof oObject[sChild] === 'object') {
							collect((sName ? sName + '/' : '') + sChild, oObject[sChild]);
						}
					});
				}
			}

			if (this.get(oObject, '/')) {
				return true;
			}

			collect('', oObject);

			return (aFilters.length > 0 ? aFilters.join(sSeparator || ',') : false);
		}
501180
public function fmap(callable $f)
    {
        return $this->fmapGen(function (RoseTree $rose) use ($f) {
            return $rose->fmap($f);
        });
    }
118499
public function getGridFS($name = 'fs')
    {
        // return from pool
        if ($this->collectionPoolEnabled && isset($this->collectionPool[$name])) {
            return $this->collectionPool[$name];
        }

        // no object in pool - init new
        $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true));
        $className = $classDefinition->getClass();

        // create collection class
        $collection = new $className($this, $name, $classDefinition);
        if (!$collection instanceof \Sokil\Mongo\GridFS) {
            throw new Exception('Must be instance of \Sokil\Mongo\GridFS');
        }

        // store to pool
        if ($this->collectionPoolEnabled) {
            $this->collectionPool[$name] = $collection;
        }

        // return
        return $collection;
    }
1261916
function(index) {
    var result = _.extend({}, index.nodes);
    _.each(index.scopes, function(child, name) {
      if (name !== "nodes") {
        _.extend(result, _collect(child));
      }
    });
    return result;
  }
1260204
public static function getInstance(array $aliases = []) : Manager
    {
        if (is_null(static::$instance)) {
            return static::$instance = new static($aliases);
        }

        static::$instance->alias($aliases);

        return static::$instance;
    }
959902
public function fetch( $alias ) {
		if ( isset( $this->classes[ $alias ] ) ) {
			// If the alias is a class name,
			// then retrieve its linked alias.
			// This is only registered when
			// registering using an array.
			$alias = $this->classes[ $alias ];
		}

		if ( ! isset( $this->aliases[ $alias ] ) ) {
			throw new UndefinedAliasException( $alias );
		}

		$value = $this->definitions[ $alias ];

		// If the shared value is a closure,
		// execute it and assign the result
		// in place of the closure.
		if ( $value instanceof \Closure ) {
			$factory = $value;
			$value   = $factory( $this );
		}

		// If the value is shared, save the shared value.
		if ( isset( $this->shared[ $alias ] ) ) {
			$this->definitions[ $alias ] = $value;
		}

		// Return the fetched value.
		return $value;
	}
1219462
public static <T, P, A> Collection<A> collectWith(
            Iterable<T> iterable,
            Function2<? super T, ? super P, ? extends A> function,
            P parameter)
    {
        if (iterable instanceof MutableCollection)
        {
            return ((MutableCollection<T>) iterable).collectWith(function, parameter);
        }
        if (iterable instanceof ArrayList)
        {
            return ArrayListIterate.collectWith((ArrayList<T>) iterable, function, parameter);
        }
        if (iterable instanceof List<?>)
        {
            return ListIterate.collectWith((List<T>) iterable, function, parameter);
        }
        if (iterable instanceof Collection)
        {
            return IterableIterate.collectWith(
                    iterable,
                    function,
                    parameter,
                    DefaultSpeciesNewStrategy.INSTANCE.<A>speciesNew(
                            (Collection<T>) iterable,
                            ((Collection<T>) iterable).size()));
        }
        if (iterable != null)
        {
            return IterableIterate.collectWith(iterable, function, parameter);
        }
        throw new IllegalArgumentException("Cannot perform a collectWith on null");
    }
1080847
final public static function parMap($xs, $f, $n = 4, $timeout = null)
    {
        $parallel = new Internal\Parallel($f, $n, $timeout);
        $parallel->pushAll($xs);
        return $parallel;
    }
651601
public function select(callable $filter)
    {
        if (! $this->collection) {
            return new ReviewCollection();
        }

        $filtered = array_filter($this->collection, $filter);

        return new ReviewCollection($filtered);
    }
102511
function groupOn(f, xs) {
    return groupBy((a, b) => f(a) === f(b), xs);
}