var b = require('ast-types').builders;
module.exports = function(scope) {
  return b.functionExpression(
  null,
  [b.identifier('array')],
  b.blockStatement([
    b.variableDeclaration(
      'var',
      [
        b.variableDeclarator(
          b.identifier('index'),
          b.literal(0)
        )
      ]
    ),
    b.returnStatement(
      b.objectExpression([
        b.property(
          'init',
          b.identifier('next'),
          b.functionExpression(
            null,
            [],
            b.blockStatement([
              b.ifStatement(
                b.binaryExpression(
                  '<',
                  b.identifier('index'),
                  b.memberExpression(
                    b.identifier('array'),
                    b.identifier('length'),
                    false
                  )
                ),
                b.blockStatement([
                  b.returnStatement(
                    b.objectExpression([
                      b.property(
                        'init',
                        b.identifier('done'),
                        b.literal(false)
                      ),
                      b.property(
                        'init',
                        b.identifier('value'),
                        b.memberExpression(
                          b.identifier('array'),
                          b.updateExpression(
                            '++',
                            b.identifier('index'),
                            false
                          ),
                          true
                        )
                      )
                    ])
                  )
                ]),
                b.blockStatement([
                  b.returnStatement(
                    b.objectExpression([
                      b.property(
                        'init',
                        b.identifier('done'),
                        b.literal(true)
                      ),
                      b.property(
                        'init',
                        b.identifier('value'),
                        b.unaryExpression(
                          'void',
                          b.literal(0),
                          true
                        )
                      )
                    ])
                  )
                ])
              )
            ]),
            false,
            false
          )
        )
      ])
    )
  ]),
  false,
  false
)};
