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


TypeScript ramda.take函數代碼示例

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


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

示例1: createLastPosition

function* createLastPosition({
  payload
}: ActionType<typeof lastPositionsCreator.createLastPosition>): SagaIterator {
  try {
    const {lastPositions = []}: LocalStorage = yield call(getLocalStorage)

    if (payload.index <= lastPositions.length) {
      if (lastPositions[payload.index] && lastPositions[payload.index].id === payload.id) {
        return
      }

      const updatedLastPositions = [
        ...R.take(payload.index, lastPositions),
        {
          id: payload.id,
          scrollTop: 0
        }
      ]

      yield call(setLocalStorage, {
        lastPositions: updatedLastPositions
      })
    }
  } catch (err) {
    console.error(err)
  }
}
開發者ID:foray1010,項目名稱:Popup-my-Bookmarks,代碼行數:27,代碼來源:saga.ts

示例2: test

  test('should remove tree and its child trees if cannot get that tree', () => {
    for (let i = 1; i < correlatedBookmarkTrees.length; i += 1) {
      const clonedGenerator = generator.clone()

      const partiallyUnrelatedBookmarkTrees = R.set(R.lensIndex(i), null, correlatedBookmarkTrees)
      expect(clonedGenerator.next(partiallyUnrelatedBookmarkTrees).value).toEqual(
        R.take(i, partiallyUnrelatedBookmarkTrees)
      )

      expect(clonedGenerator.next().done).toBe(true)
    }
  })
開發者ID:foray1010,項目名稱:Popup-my-Bookmarks,代碼行數:12,代碼來源:getters.test.ts

示例3: describe

describe('getBookmarkTrees', () => {
  // limit to 4 trees, and set parentId to previous tree id
  const correlatedBookmarkTrees = R.take(4, bookmarkTrees).reduce(
    (acc: Array<BookmarkTree>, bookmarkTree) => {
      if (!acc.length) return [bookmarkTree]

      const prevBookmarkTree = R.last(acc)
      if (!prevBookmarkTree) throw new Error('prevBookmarkTree must exist')
      const updatedBookmarkTree = R.set(
        R.lensPath(['parent', 'parentId']),
        prevBookmarkTree.parent.id,
        bookmarkTree
      )
      return [...acc, updatedBookmarkTree]
    },
    []
  )
  const getRestTreeIds = (trees: Array<BookmarkTree>) => R.tail(trees).map((tree) => tree.parent.id)

  const options = optionsFixture
  const restTreeIds = getRestTreeIds(correlatedBookmarkTrees)

  const generator = cloneableGenerator(getters.getBookmarkTrees)(restTreeIds, options)

  expect(generator.next().value).toEqual(
    all([
      call(getters.getFirstBookmarkTree, options),
      ...R.map((id) => call(getters.tryGetBookmarkTree, id), restTreeIds)
    ])
  )

  test('should get all trees', () => {
    const clonedGenerator = generator.clone()

    expect(clonedGenerator.next(correlatedBookmarkTrees).value).toEqual(correlatedBookmarkTrees)

    expect(clonedGenerator.next().done).toBe(true)
  })
  test('should remove tree and its child trees if cannot get that tree', () => {
    for (let i = 1; i < correlatedBookmarkTrees.length; i += 1) {
      const clonedGenerator = generator.clone()

      const partiallyUnrelatedBookmarkTrees = R.set(R.lensIndex(i), null, correlatedBookmarkTrees)
      expect(clonedGenerator.next(partiallyUnrelatedBookmarkTrees).value).toEqual(
        R.take(i, partiallyUnrelatedBookmarkTrees)
      )

      expect(clonedGenerator.next().done).toBe(true)
    }
  })
})
開發者ID:foray1010,項目名稱:Popup-my-Bookmarks,代碼行數:51,代碼來源:getters.test.ts

示例4: getVocabulary

  public getVocabulary(id: string): string[] {
    if (this.getId() === id) {
      return this.getNewVocabulary();
    }

    const nodesUntilId = takeWhile(
      found => !found,
      map(child => child.findEntity(id), this.getChildren())
    );
    const previousChildren = take(nodesUntilId.length + 1, this.getChildren());

    return concat(
      flatten<string>(map(node => node.getVocabulary(id), previousChildren)),
      this.getNewVocabulary()
    );
  }
開發者ID:serlo-org,項目名稱:serlo-abc,代碼行數:16,代碼來源:InternalNode.ts

示例5: removeLastPosition

function* removeLastPosition({
  payload
}: ActionType<typeof lastPositionsCreator.removeLastPosition>): SagaIterator {
  try {
    const {lastPositions = []}: LocalStorage = yield call(getLocalStorage)

    if (payload.index <= lastPositions.length - 1) {
      const updatedLastPositions = R.take(payload.index, lastPositions)

      yield call(setLocalStorage, {
        lastPositions: updatedLastPositions
      })
    }
  } catch (err) {
    console.error(err)
  }
}
開發者ID:foray1010,項目名稱:Popup-my-Bookmarks,代碼行數:17,代碼來源:saga.ts

示例6: apply

export default function apply(config: Config) {
  let client = config.client;
  let command = config.commands.apply;

  let migrations = listMigrations(config.files.directory);
  let journal = readJournal(client.name, client.config, client.journalTable);
  let states = Promise.join(migrations, journal, getMigrationStates)

  let applicableIDs = states
    .then(R.filter(isApplicable))
    .then(ss => R.map(s => s.migrationID, ss));
  let toApplyIDs: Promise<string[]>;

  if (command.pending) {
    toApplyIDs = applicableIDs;
  } else if (command.id) {
    toApplyIDs = applicableIDs.then(R.filter(id => id === command.id));
  } else if (command.to) {
    toApplyIDs = applicableIDs.then(R.filter(id => id <= command.to));
  } else if (command.number) {
    toApplyIDs = applicableIDs.then(R.take(command.number));
  } else {
    toApplyIDs = Promise.resolve([]);
  }

  let toApply = Promise.join(migrations, toApplyIDs, (ms, ids) =>
    R.filter(m => R.contains(m.id, ids), ms)
  );

  let apply = toApply.then(ms =>
    applyFunction(command.method)(
      client.name, client.config, client.journalTable, ms
    )
  );

  let previousEntry = journal.then(es => R.last(es));
  let newEntries = Promise.join(previousEntry, apply, (prev, es) =>
    prev ? R.filter(e => e.timestamp > prev.timestamp, es) : apply
  );

  return newEntries
    .then(R.map(formatJournalEntry))
    .then(R.join(''));
}
開發者ID:programble,項目名稱:careen,代碼行數:44,代碼來源:apply.ts

示例7: getLetters

  public getLetters(id: string): string[] {
    const newLetterArr: string[] = this.getNewLetter()
      ? ([this.getNewLetter()] as string[])
      : [];
    if (this.getId() === id) {
      return newLetterArr;
    }

    const nodesUntilId = takeWhile(
      found => !found,
      map(child => child.findEntity(id), this.getChildren())
    );
    const previousChildren = take(nodesUntilId.length + 1, this.getChildren());

    return concat(
      flatten<string>(map(node => node.getLetters(id), previousChildren)),
      newLetterArr
    );
  }
開發者ID:serlo-org,項目名稱:serlo-abc,代碼行數:19,代碼來源:InternalNode.ts

示例8: revert

export default function revert(config: Config) {
  let client = config.client;
  let command = config.commands.revert;

  let migrations = listMigrations(config.files.directory);
  let journal = readJournal(client.name, client.config, client.journalTable);
  let states = Promise.join(migrations, journal, getMigrationStates);

  let revertableIDs = states
    .then(R.filter(isRevertable))
    .then(ss => R.map(s => s.migrationID, ss));
  let toRevertIDs: Promise<string[]>;

  if (command.id) {
    toRevertIDs = revertableIDs.then(R.filter(id => id === command.id));
  } else if (command.to) {
    toRevertIDs = revertableIDs.then(R.filter(id => id > command.to));
  } else if (command.number) {
    toRevertIDs = revertableIDs.then(R.reverse).then(R.take(command.number));
  } else {
    toRevertIDs = Promise.resolve([]);
  }

  let toRevert = Promise.join(migrations, toRevertIDs, (ms, ids) =>
    R.filter(m => R.contains(m.id, ids), R.reverse(ms))
  );

  let revert = toRevert.then(ms =>
    revertFunction(command.method)(
      client.name, client.config, client.journalTable, ms
    )
  );

  let previousEntry = journal.then(es => R.last(es));
  let newEntries = Promise.join(previousEntry, revert, (prev, es) =>
    R.filter(e => e.timestamp > prev.timestamp, es)
  );

  return newEntries
    .then(R.map(formatJournalEntry))
    .then(R.join(''));
}
開發者ID:programble,項目名稱:careen,代碼行數:42,代碼來源:revert.ts

示例9: take

 updateRight<Event[], Event[]>((prevEvents, events) => take(100, events)),
開發者ID:displague,項目名稱:manager,代碼行數:1,代碼來源:event.helpers.ts

示例10: equals

const isSpare = rolls => equals(10, sum(take(2, rolls)));
開發者ID:sprengerjo,項目名稱:katas_js,代碼行數:1,代碼來源:bowling_score_calculator.ts


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