---
name: "UR::Object::Iterator"
section: "3pm"
platform: "linux"
package: "libur-perl"
version: "0.470+ds-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/UR::Object::Iterator"
---

# UR::Object::Iterator(3pm)

API for iterating through objects matching a rule

## NAME

UR::Object::Iterator - API for iterating through objects matching a rule

## SYNOPSIS

```
  my $rule = UR::BoolExpr->resolve('Some::Class', foo => 1);
  my $iter = UR::Object::Iterator->create_for_filter_rule($rule);
  while (my $obj = $iter->next()) {
      print "Got an object: ",$obj->id,"\n";
  }
  # Equivalent
  my $iter2 = Some::Class->create_iterator(foo => 1);
  while (my $obj = $iter2->next()) {
      print "Got an object: ",$obj->id,"\n";
  }
```

## DESCRIPTION

**get()**, implemented in UR::Object, is the usual way for retrieving sets of objects matching particular properties.  When the result set of data is large, it is often more efficient to use an iterator to access the data  instead of getting it all in one list.

UR::Object implements **create\_iterator()**, which is just a wrapper around **create\_for\_filter\_rule()**.

UR::Object::Iterator instances are normal Perl object references, not UR-based objects.  They do not live in the Context's object cache, and obey the normal Perl rules about scoping.

## CONSTRUCTOR

- create\_for\_filter\_rule

  ```
    $iter = UR::Object::Iterator->create_for_filter_rule($boolexpr);
  ```

  Creates an iterator object based on the given BoolExpr (rule).  Under the hood, it calls **get\_objects\_for\_class\_and\_rule()** on the current Context with the `$return_closure` flag set to true.

### Methods inherited from UR::Iterator

- next

  - map

  - peek

  - remaining

  ## SEE ALSO

UR::Iterator, UR::Object, UR::Context
