當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ramda.reduce函數代碼示例

本文整理匯總了TypeScript中ramda.reduce函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript reduce函數的具體用法?TypeScript reduce怎麽用?TypeScript reduce使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了reduce函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getAddress

  /**
   * Return a string of a formatted address
   * @param fields The array of address fields
   */
  static getAddress(fields: Array<string>): string {
    let str = '';
    const concat = R.reduce((a, b) => {
      if (R.isEmpty(b) || R.isNil(b)) { return a }
      return a + '\n' + b
    }, '');

    return concat(fields);
  }
開發者ID:simbiosis-group,項目名稱:ion2-helper,代碼行數:13,代碼來源:formatter.ts

示例2: getAllInDirectory

export function getAllInDirectory (directory: string): Array<string> {
  return reduce((files: string[], file: string) => {
    const abspath = join(directory, file);

    if (isFile(abspath))
      return append(file, files);

    if (isDirectory(abspath))
      return concat(files,
        getAllInDirectory(abspath).map((f: string) => join(relative(directory, abspath), f)));

    return files;
  }, [], fs.readdirSync(directory));
}
開發者ID:TylorS,項目名稱:ts-lib,代碼行數:14,代碼來源:fs.ts

示例3: relationExtractor

export function relationExtractor(model): string[] {

  let keys = Object.keys(model.tableAttributes);

  function modelReducer(acc, key) {

    if (!R.isNil(model.tableAttributes[key].references)) {
      acc.push(model.tableAttributes[key].references.model);
      // references.model here is the name of the table
    }

    return acc;
  }

  return R.reduce(modelReducer, [], keys);
};
開發者ID:repositive,項目名稱:hapi-path-generator,代碼行數:16,代碼來源:modelRelations.ts

示例4:

export const sendEmail$ = (applicant) => {
	const cc = 'anli@simbiosis.com.sg';
	const array = R.reject(R.isNil)([
		applicant.hasSps ? 'SPS' : null,
		applicant.hasSrp ? 'SRP' : null,
		applicant.hasSrpSupervisor ? 'SRP Approved Supervisor' : null,
	]);
	const applicantText = R.reduce((a, n) => (a === '') ? n : `${a}, ${n}`, '')(array);
	const text = `<p>Dear ${applicant.applicantName}</p><p>We have received your ${applicantText} applicant package.</p><p>We will keep you updated on the progress.</p><p>Thank you</p>`;

	return this.mailgun.send$(`${applicant.applicantEmail}`, 'Applicant Received', text, cc)
		.first()
		.catch(err => {
			console.log(err);
			return Observable.of(err)
		})
}
開發者ID:simbiosis-group,項目名稱:ion2-member,代碼行數:17,代碼來源:applicant.model.ts

示例5: next

export async function removeSetCookie<T extends IOClients, U, V> (ctx: ServiceContext<T, U, V>, next: () => Promise<any>) {
  const { clients: { logger } } = ctx

  await next()

  const setCookie: string[] | undefined = ctx.response.headers['set-cookie']
  if (!setCookie || isEmpty(setCookie)) {
    return
  }

  const cacheControl: string | undefined = ctx.response.headers['cache-control']
  const scope = findScopeInCacheControl(cacheControl)
  if (scope === 'public') {
    const indexedCookies = indexCookieByKeys(setCookie)
    const cookies = reduce(
      (acc, [key, payload]) => {
        if (BLACKLISTED_COOKIES.has(key)) {
          acc.droppedKeys.push(key)
        } else {
          acc.addedPayload.push(payload)
        }
        return acc
      },
      {
        addedPayload: [],
        droppedKeys: [],
      } as CookieAccumulator,
      indexedCookies
    )

    if (cookies.droppedKeys.length > 0) {
      ctx.set('set-cookie', cookies.addedPayload)
      console.warn(warnMessage(cookies.droppedKeys))
      logger.warn({
        cookieKeys: cookies.droppedKeys,
        message: 'Setting cookies in a public route!',
      }).catch()
    }
  }
}
開發者ID:vtex,項目名稱:apps-client-node,代碼行數:40,代碼來源:setCookie.ts

示例6: put

          const isSysAdmin = !!R.find(role => role.name === 'SYS_ADMIN')(currentRoles);
          logger.debug('[init]', 'current user isSysAdmin', isSysAdmin);

          const authoritiesList = R.compose(
            // remove null values
            R.filter(R.identity),
            // 後端返回字符串時需要反序列化為 JSON
            R.map(role => {
              const each = R.prop('authorities')(role);
              return R.is(String, each) ? JSON.parse(each) : each;
            }),
          )(currentRoles);
          logger.debug('[init]', 'current authoritiesList is', authoritiesList);

          const authorities = R.reduce(R.mergeWith(R.or), {})(authoritiesList);
          logger.debug('[init]', 'current authorities is', authorities);

          const menus = yield menuProxy.init(isSysAdmin, authorities);
          logger.log('[init]', 'init sage, menus is', menus);

          yield put({ type: menuActionTypes.INIT_SUCCESS, payload: { menus } });
        } else {
          logger.warn('[init]', 'cannot found any roles');
        }
      } else {
        logger.warn('[init]', 'cannot found current user');
      }
    } catch (e) {
      logger.error('[init]', e);
    }
開發者ID:danielwii,項目名稱:asuna-admin,代碼行數:30,代碼來源:menu.redux.ts

示例7: UpdatesState

 webHookUpdates.map((updates: TcombUpdate[]) => UpdatesState({
   startDate: initialState.startDate,
   offset: reduce(max('update_id'), 0, updates) + 1,
   updates
 })))
開發者ID:goodmind,項目名稱:cycle-telegram,代碼行數:5,代碼來源:sources.ts

示例8: typeof

  if (device === null) {
    return result;
  }

  if (isDisk(device)) {
    return { ...result, [key]: `disk-${device.disk_id}` };
  }

  if (isVolume(device)) {
    return { ...result, [key]: `volume-${device.volume_id}` };
  }

  return result;
};

const isDisk = (
  device: Linode.DiskDevice | Linode.VolumeDevice
): device is Linode.DiskDevice => {
  return typeof (device as Linode.DiskDevice).disk_id === 'number';
};
const isVolume = (
  device: Linode.DiskDevice | Linode.VolumeDevice
): device is Linode.VolumeDevice => {
  return typeof (device as Linode.VolumeDevice).volume_id === 'number';
};

export default compose(
  reduce(rdx, {}),
  toPairs
);
開發者ID:linode,項目名稱:manager,代碼行數:30,代碼來源:createStringsFromDevices.ts

示例9: reduce

const reduceEntries = <T>(fn: (T, any) => T, acc: T) => obj => reduce(fn, acc, Object.entries(obj));
開發者ID:benjambles,項目名稱:my-own-world,代碼行數:1,代碼來源:reduce-entries.ts


注:本文中的ramda.reduce函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。