How to use the iterall.forEach function in iterall

To help you get started, we’ve selected a few iterall examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-factory / graphql-factory / archive / execution / complete.js View on Github external
execDetails: ObjMap
): mixed {
  invariant(
    isCollection(result),
    `Expected Iterable, but did not find one for field ${
      info.parentType.name}.${info.fieldName}.`
  );

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType;
  let containsPromise = false;
  const completedResults = [];
  execDetails.type = LoggerDetailType.LIST_FIELD;

  forEach((result: any), (item, index) => {
    const itemDetails = {
      type: LoggerDetailType.LIST_ITEM,
      name: String(index),
      resolver: '',
      start: Date.now(),
      end: -1,
      duration: -1,
      error: null,
      args: {},
      resolves: []
    };
    execDetails.resolves.push(itemDetails);
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index);
    const completedItem = completeValueCatchingError(
github graphql-factory / graphql-factory / src-old / execution / execute.js View on Github external
result: mixed,
  tracing: ObjMap,
): MaybePromise<$ReadOnlyArray> {
  invariant(
    isCollection(result),
    `Expected Iterable, but did not find one for field ${
      info.parentType.name
    }.${info.fieldName}.`,
  );

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType;
  let containsPromise = false;
  const completedResults = [];
  forEach((result: any), (item, index) => {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index);

    // start a field trace
    const fieldTrace = {
      type: 'FIELD',
      resolver: exeContext.fieldResolver.name,
      path: responsePathAsArray(fieldPath),
      location: null,
      parentType: String(info.parentType),
      fieldName: info.fieldName,
      returnType: String(returnType),
      start: getTime(),
      end: -1,
      duration: -1,
github graphql / graphql-js / src / utilities / coerceInputValue.js View on Github external
`Expected non-nullable type "${inspect(type)}" not to be null.`,
      ),
    );
    return;
  }

  if (inputValue == null) {
    // Explicitly return the value null.
    return null;
  }

  if (isListType(type)) {
    const itemType = type.ofType;
    if (isCollection(inputValue)) {
      const coercedValue = [];
      forEach((inputValue: any), (itemValue, index) => {
        coercedValue.push(
          coerceInputValueImpl(
            itemValue,
            itemType,
            onError,
            addPath(path, index),
          ),
        );
      });
      return coercedValue;
    }
    // Lists accept a non-list value as a list of one.
    return [coerceInputValueImpl(inputValue, itemType, onError, path)];
  }

  if (isInputObjectType(type)) {
github graphql / graphql-js / src / utilities / astFromValue.js View on Github external
if (value === null) {
    return { kind: Kind.NULL };
  }

  // undefined, NaN
  if (isInvalid(value)) {
    return null;
  }

  // Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
  // the value is not an array, convert the value using the list's item type.
  if (isListType(type)) {
    const itemType = type.ofType;
    if (isCollection(value)) {
      const valuesNodes = [];
      forEach((value: any), item => {
        const itemNode = astFromValue(item, itemType);
        if (itemNode) {
          valuesNodes.push(itemNode);
        }
      });
      return { kind: Kind.LIST, values: valuesNodes };
    }
    return astFromValue(value, itemType);
  }

  // Populate the fields of the input object by creating ASTs from each value
  // in the JavaScript object according to the fields in the input type.
  if (isInputObjectType(type)) {
    if (!isObjectLike(value)) {
      return null;
    }
github scaphold-io / graphql-extended / src / execution / execute.ts View on Github external
path: ResponsePath,
  result: mixed,
  middlewareContext: MiddlewareContext,
): mixed {
  invariant(
    isCollection(result),
    `Expected Iterable, but did not find one for field ${
      info.parentType.name}.${info.fieldName}.`,
  )

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType
  let containsPromise = false
  const completedResults: Array = []
  forEach(result as Array, (item, index) => {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index)
    const completedItem = completeValueCatchingError(
      exeContext,
      itemType,
      fieldNodes,
      info,
      fieldPath,
      item,
      middlewareContext,
    )

    if (!containsPromise && getPromise(completedItem)) {
      containsPromise = true
    }
github mobxjs / mobx / test / base / array.js View on Github external
test("array should support iterall / iterable ", () => {
    var a = observable([1, 2, 3])

    expect(iterall.isIterable(a)).toBe(true)
    expect(iterall.isArrayLike(a)).toBe(true)

    var values = []
    iterall.forEach(a, v => values.push(v))

    expect(values).toEqual([1, 2, 3])

    var iter = iterall.getIterator(a)
    expect(iter.next()).toEqual({ value: 1, done: false })
    expect(iter.next()).toEqual({ value: 2, done: false })
    expect(iter.next()).toEqual({ value: 3, done: false })
    expect(iter.next()).toEqual({ value: undefined, done: true })

    a.replace([])
    iter = iterall.getIterator(a)
    expect(iter.next()).toEqual({ value: undefined, done: true })
})
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
function check(value) {
        expect(Object.isFrozen(value)).toBe(true);
        if (isCollection(value)) {
          forEach(value, check);
        } else if (typeof value === 'object' && value !== null) {
          for (const key in value) {
            check(value[key]);
          }
        }
      }
      check(actual);
github winoteam / react-router-navigation / packages / react-router-navigation-core / src / StateUtils.js View on Github external
(state, item) => {
          let entry
          forEach(historyEntries, (_entry, index) => {
            if (!entry) {
              const entryIndex = historyEntries.length - 1 - index
              const currentEntry = historyEntries[entryIndex]
              if (currentEntry && matchPath(currentEntry.pathname, item)) {
                entry = currentEntry
              }
            }
          })
          const match = entry ? matchPath(entry.pathname, item) : null
          const staleRoute = staleRoutes && staleRoutes[state.routes.length]
          const route = RouteUtils.create(item, match && entry, staleRoute)
          if (!route) return state
          const isCurrentLocation =
            entry && entry.pathname === location.pathname
          return {
            routes: [...state.routes, route],