@sullux/fp-light-take

0.0.1 • Public • Published

home

fp-light-skip

npm i @sullux/fp-light-skip source test

Creates an iterable that takes the first n items of the given iterable.

skip

skip<T>(count: number, iterable: Iterable<T>): Iterable<T>

If count is less than 1, yields no items; otherwise, yields count items. If count is greater than the number of items in the iterable, yields all items.

const { take } = require('./take')
const { deepStrictEqual } = require('assert')

describe('take', () => {
  it('should take all values when given length', () => deepStrictEqual(
    [...take(3, [1, 2, 3])],
    [1, 2, 3]
  ))
  it('should take all values when given greater than length', () => deepStrictEqual(
    [...take(4, [1, 2, 3])],
    [1, 2, 3]
  ))
  it('should take some values when given less than length', () => deepStrictEqual(
    [...take(2, [1, 2, 3])],
    [1, 2]
  ))
  it('should return empty when given zero', () => deepStrictEqual(
    [...take(0, [1, 2, 3])],
    []
  ))
  it('should return empty when given less than zero', () => deepStrictEqual(
    [...take(-1, [1, 2, 3])],
    []
  ))
})

Readme

Keywords

Package Sidebar

Install

npm i @sullux/fp-light-take

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

2.07 kB

Total Files

3

Last publish

Collaborators

  • sullux