• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ramda.reduce函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 = '[email protected]';
	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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ramda.reject函数代码示例发布时间:2022-05-25
下一篇:
TypeScript ramda.range函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap