An iterator that maps each item to an iterator and yield

each item from it.

Introduced properties

protected fun f=(f: Fun1[A, Iterator[B]])

functional :: FlatMapIter :: f=

protected fun inner: nullable Iterator[B]

functional :: FlatMapIter :: inner

protected fun inner=(inner: nullable Iterator[B])

functional :: FlatMapIter :: inner=

protected fun try_compute_inner

functional :: FlatMapIter :: try_compute_inner

Tries to resolve the inner iterator.

Redefined properties

redef type SELF: FlatMapIter[A, B]

functional $ FlatMapIter :: SELF

Type of this instance, automatically specialized in every class
redef init init

functional $ FlatMapIter :: init

redef fun is_ok: Bool

functional $ FlatMapIter :: is_ok

Is there a current item ?
redef fun item: B

functional $ FlatMapIter :: item

The current item.
redef fun next

functional $ FlatMapIter :: next

Jump to the next item.

All properties

type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun f=(f: Fun1[A, Iterator[B]])

functional :: FlatMapIter :: f=

init init

core :: Object :: init

protected fun inner: nullable Iterator[B]

functional :: FlatMapIter :: inner

protected fun inner=(inner: nullable Iterator[B])

functional :: FlatMapIter :: inner=

abstract fun is_ok: Bool

core :: Iterator :: is_ok

Is there a current item ?
abstract fun item: E

core :: Iterator :: item

The current item.
abstract fun next

core :: Iterator :: next

Jump to the next item.
protected fun try_compute_inner

functional :: FlatMapIter :: try_compute_inner

Tries to resolve the inner iterator.
package_diagram functional::FlatMapIter FlatMapIter

Ancestors

interface Iterator[E: nullable Object]

core :: Iterator

Iterators generate a series of elements, one at a time.
interface Object

core :: Object

The root of the class hierarchy.

Class definitions

functional $ FlatMapIter
# An iterator that maps each item to an iterator and yield
# each item from it.
class FlatMapIter[A,B]
        super FunIter[A,B]
        var f: Fun1[A, Iterator[B]]
        protected var inner: nullable Iterator[B] = null

        redef init
        do
                try_compute_inner
        end

        redef fun item
        do
                return inner.as(not null).item
        end

        redef fun is_ok
        do
                return inner != null
        end

        redef fun next
        do
                inner.next
                if not inner.is_ok then
                        super
                        try_compute_inner
                end
        end

        # Tries to resolve the inner iterator.
        # Assigns null to `inner` if it fails.
        protected fun try_compute_inner
        do
                inner = null
                if not my_iter.is_ok then return
                var res = f.call(my_iter.item)
                if res.is_ok then inner = res
        end
end
lib/functional/iter_extras.nit:310,1--350,3