/*
Fluent filter operation using primitive types
e.g.
<pre>
{@code
import static cyclops.ReactiveSeq.filterInts;

ReactiveSeq.ofInts(1,2,3)
.to(filterInts(i->i>2));

//[3]
}
</pre>
170652
public static Function<? super ReactiveSeq<Integer>, ? extends ReactiveSeq<Integer>> filterInts(IntPredicate b){

        return a->a.ints(i->i,s->s.filter(b));
    }
1139880
function filterfrom(filter, o) {
		var t = filter(o);
		if (gui.Type.isConstructor(t)) {
			t = constructas(t, o);
		} else if (edb.Type.is(t) || t === null) {
			t = t;
		} else {
			fail(
				'edb.Type constructor or instance',
				gui.Type.of(t),
				'return null for nothing'
			);
		}
		return t;
	}
603743
public static <T, E extends Exception> List<T> filter(final T[] a, final int fromIndex, final int toIndex, final Try.Predicate<? super T, E> filter,
            final int max) throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(filter);

        if (N.isNullOrEmpty(a)) {
            return new ArrayList<>();
        }

        final List<T> result = new ArrayList<>(min(9, max, (toIndex - fromIndex)));

        for (int i = fromIndex, cnt = 0; i < toIndex && cnt < max; i++) {
            if (filter.test(a[i])) {
                result.add(a[i]);
                cnt++;
            }
        }

        return result;
    }
270475
@VisibleForTesting
    public static boolean checkInBloomFilter(BloomFilter bloomFilter, Object predicateValue, Type sqlType)
    {
        if (sqlType == TINYINT || sqlType == SMALLINT || sqlType == INTEGER || sqlType == BIGINT) {
            return bloomFilter.testLong(((Number) predicateValue).longValue());
        }

        if (sqlType == DOUBLE) {
            return bloomFilter.testDouble((Double) predicateValue);
        }

        if (sqlType instanceof VarcharType || sqlType instanceof VarbinaryType) {
            return bloomFilter.test(((Slice) predicateValue).getBytes());
        }

        // todo support DECIMAL, FLOAT, DATE, TIMESTAMP, and CHAR
        return true;
    }
401858
@Override
    public ObjectData compileObjectType(Set<String> filter, Boolean includeAllowableActions,
            ObjectInfoHandler objectInfos, boolean requiresObjectInfo) {

        try {
            ObjectDataImpl result = new ObjectDataImpl();
            ObjectInfoImpl objectInfo = new ObjectInfoImpl();

            PropertiesImpl properties = new PropertiesImpl();
            filter = filter == null ? null : new HashSet<>(filter);
            compileProperties(properties, filter, objectInfo);
            result.setProperties(properties);

            if (Boolean.TRUE.equals(includeAllowableActions)) {
                result.setAllowableActions(getAllowableActions());
            }

            if (requiresObjectInfo) {
                objectInfo.setObject(result);
                objectInfos.addObjectInfo(objectInfo);
            }

            return result;
        } catch (RepositoryException e) {
            throw new CmisRuntimeException(e.getMessage(), e);
        }
    }
607561
@Override
    public ImmutableSubstitution<ImmutableTerm> composeWith(ImmutableSubstitution<? extends ImmutableTerm> f) {
        if (isEmpty()) {
            return (ImmutableSubstitution<ImmutableTerm>)f;
        }
        if (f.isEmpty()) {
            return (ImmutableSubstitution<ImmutableTerm>)this;
        }

        Map<Variable, ImmutableTerm> substitutionMap = new HashMap<>();

        /**
         * For all variables in the domain of f
         */

        for (Map.Entry<Variable, ? extends ImmutableTerm> gEntry :  f.getImmutableMap().entrySet()) {
            substitutionMap.put(gEntry.getKey(), apply(gEntry.getValue()));
        }

        /**
         * For the other variables (in the local domain but not in f)
         */
        for (Map.Entry<Variable, ? extends ImmutableTerm> localEntry :  getImmutableMap().entrySet()) {
            Variable localVariable = localEntry.getKey();

            if (substitutionMap.containsKey(localVariable))
                continue;

            substitutionMap.put(localVariable, localEntry.getValue());
        }

        return substitutionFactory.getSubstitution(
                substitutionMap.entrySet().stream()
                        // Clean out entries like t/t
                        .filter(entry -> !entry.getKey().equals(entry.getValue()))
                        .collect(ImmutableCollectors.toMap()));
    }
1146599
public final FluentCloseableIterable<T> filter(Predicate<? super T> predicate) {
        return from(CloseableIterables.filter(this, predicate));
    }
225394
public static Function<? super ReactiveSeq<Integer>, ? extends ReactiveSeq<Integer>> concatInts( ReactiveSeq<Integer> b){
        return a->ReactiveSeq.fromSpliterator(IntStream.concat(a.mapToInt(i->i),b.mapToInt(i->i)).spliterator());
    }
78070
private List<Integer> calculateRowsToFilter(DataView dataView, FilterQuery filterQuery, DataSchema schema) {
        JsArray<JavaScriptObject> propertiesJsArray = convertToColumnIndexAndValueArray(filterQuery, schema);
        JsArrayInteger jsArrayInteger = getFilteredRows(dataView, propertiesJsArray);
        return toTypedObjectArray(jsArrayInteger);
    }
642467
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> filterLongs(LongPredicate b){

        return a->a.longs(i->i,s->s.filter(b));
    }
701771
@CheckReturnValue
  public final FluentIterable<E> filter(Predicate<? super E> predicate) {
    return from(Iterables.filter(iterable, predicate));
  }
388077
public static Function<? super ReactiveSeq<Integer>, ? extends ReactiveSeq<Integer>> skipInts(long skip){

        return a->a.ints(i->i,s->s.skip(skip));
    }
1193503
public final <E> FluentCloseableIterable<E> filter(Class<E> type) {
        return from(CloseableIterables.filter(this, type));
    }
310696
private FilterUtils refine(final Map<QName, Map<String, Set<Element>>> bindingMap) {
        if (bindingMap != null && !bindingMap.isEmpty()) {
            final Map<FilterKey, Action> buf = new HashMap<>(filterMap);
            for (final Map.Entry<FilterKey, Action> e: filterMap.entrySet()) {
                refineAction(e.getValue(), e.getKey(), bindingMap, buf);
            }
            final FilterUtils filterUtils = new FilterUtils(buf, foregroundConflictColor, backgroundConflictColor);
            filterUtils.setLogger(logger);
            filterUtils.logMissingAction = logMissingAction;
            return filterUtils;
        } else {
            return this;
        }
    }
40444
public static <T, IV> int detectIndexWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue)
    {
        int size = list.size();
        for (int i = 0; i < size; i++)
        {
            if (predicate.accept(list.get(i), injectedValue))
            {
                return i;
            }
        }
        return -1;
    }
663169
public static Function<? super ReactiveSeq<Integer>, ? extends ReactiveSeq<Integer>> concatMapnts(IntFunction<? extends IntStream> b){

        return a->a.ints(i->i,s->s.flatMap(b));
    }
735147
function genComponentProtoCode(component) {
    var code = ['{'];

    // members for call expr
    var ComponentProto = component.constructor.prototype;
    Object.keys(ComponentProto).forEach(function (protoMemberKey) {
        var protoMember = ComponentProto[protoMemberKey];
        if (COMPONENT_RESERVED_MEMBERS[protoMemberKey] || !protoMember) {
            return;
        }

        switch (typeof protoMember) {
            case 'function':
                code.push(protoMemberKey + ': ' + protoMember.toString() + ',');
                break;

            case 'object':
                code.push(protoMemberKey + ':');

                if (protoMember instanceof Array) {
                    code.push('[');
                    protoMember.forEach(function (item) {
                        code.push(typeof item === 'function' ? item.toString() : '' + ',');
                    });
                    code.push(']');
                }
                else {
                    code.push('{');
                    Object.keys(protoMember).forEach(function (itemKey) {
                        var item = protoMember[itemKey];
                        if (typeof item === 'function') {
                            code.push(itemKey + ':' + item.toString() + ',');
                        }
                    });
                    code.push('}');
                }

                code.push(',');
        }
    });

    // filters
    code.push('filters: {');
    var filterCode = [];
    for (var key in component.filters) {
        if (component.filters.hasOwnProperty(key)) {
            var filter = component.filters[key];

            if (typeof filter === 'function') {
                filterCode.push(key + ': ' + filter.toString());
            }
        }
    }
    code.push(filterCode.join(','));
    code.push('},');

    /* eslint-disable no-redeclare */
    // computed obj
    code.push('computed: {');
    var computedCode = [];
    var computedNamesCode = [];
    var computedNamesIndex = {};
    for (var key in component.computed) {
        if (component.computed.hasOwnProperty(key)) {
            var computed = component.computed[key];

            if (typeof computed === 'function') {
                if (!computedNamesIndex[key]) {
                    computedNamesIndex[key] = 1;
                    computedNamesCode.push('"' + key + '"');
                }

                computedCode.push(key + ': '
                    + computed.toString()
                        .replace(/^\s*function\s*\(/, 'function (componentCtx')
                        .replace(
                            /this.data.get\(([^\)]+)\)/g,
                            function (match, exprLiteral) {
                                var exprStr = (new Function('return ' + exprLiteral))();
                                var expr = parseExpr(exprStr);

                                var ident = expr.paths[0].value;
                                if (component.computed.hasOwnProperty(ident)
                                    && !computedNamesIndex[ident]
                                ) {
                                    computedNamesIndex[ident] = 1;
                                    computedNamesCode.unshift('"' + ident + '"');
                                }

                                return compileExprSource.expr(expr);
                            }
                        )
                );
            }
        }
    }
    code.push(computedCode.join(','));
    code.push('},');

    // computed names
    code.push('computedNames: [');
    code.push(computedNamesCode.join(','));
    code.push('],');
    /* eslint-enable no-redeclare */

    // tagName
    code.push('tagName: "' + component.tagName + '"');
    code.push('};');

    return code.join('\n');
}