How to use the iterall.getIterator 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 mobxjs / mobx / test / base / set.js View on Github external
test("set should support iterall / iterable ", () => {
    const a = set([1, 2])

    function leech(iter) {
        const values = []
        let v
        do {
            v = iter.next()
            if (!v.done) values.push(v.value)
        } while (!v.done)
        return values
    }

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

    expect(leech(iterall.getIterator(a))).toEqual([1, 2])

    expect(leech(a.entries())).toEqual([[1, 1], [2, 2]])

    expect(leech(a.keys())).toEqual([1, 2])
    expect(leech(a.values())).toEqual([1, 2])
})
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 mobxjs / mobx / test / base / map.js View on Github external
test("map should support iterall / iterable ", () => {
    const a = mobx.observable.map({ a: 1, b: 2 })

    function leech(iter) {
        const values = []
        let v
        do {
            v = iter.next()
            if (!v.done) values.push(v.value)
        } while (!v.done)
        return values
    }

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

    expect(leech(iterall.getIterator(a))).toEqual([["a", 1], ["b", 2]])

    expect(leech(a.entries())).toEqual([["a", 1], ["b", 2]])

    expect(leech(a.keys())).toEqual(["a", "b"])
    expect(leech(a.values())).toEqual([1, 2])
})
github mobxjs / mobx / test / base / array.js View on Github external
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 })
})