Giter VIP home page Giter VIP logo

sf-problem1's Introduction

The Rewindable Entity Iterator

Our EntityIterators are composed of a standard PDO PreparedStatement and a DataMapper. The DataMapper maps rows into objects in real time as we iterate over the the Statement. There is a limitation with PDO Statements in that you can only iterate over them one time.

For example:

// first loop works fine
foreach($statement as $result) {
    // do something with result
}

// but subsequent loops don't
foreach($statement as $result) {
    // never called 
}

Since our EntityIterator operates by iterating over the statement it can also only be looped over once. This causes all sorts of problems.

Your Job

Derive a RewindableEntityIterator from the EntityIterator class. Your new iterator should be rewindable and thus able to iterate over its elements repeatedly. To simplify the task we have used a ResultSet object instead of a PDO Statement. The EntityIterator iterates over the ResultSet object directly. Like the PDO Statement, the ResultSet does not have the ability to rewind.

A few constraints and notes

  • Implement the RewindableEntityIterator class in the src directory
  • Do not alter any other files in the src directory
  • There are quite a few corner cases to consider
  • There is a PHPUnit test file in the tests directory - add additional tests if it's helpful to you.
  • Be conscious of time & space complexity

Good luck

sf-problem1's People

Contributors

ryanhollister avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.