# Write better jobs with the Lazy State Operator

**URL:** <https://community.openfn.org/t/write-better-jobs-with-the-lazy-state-operator/432>\
**Category:** Job Writing\
**Created:** [April 26, 2024, 9:21am UTC](https://community.openfn.org/t/write-better-jobs-with-the-lazy-state-operator/432 "2024-04-26T09:21:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://community.openfn.org/user_avatar/community.openfn.org/joe/32/75_2.png) [@joe](https://community.openfn.org/u/joe)\
**Post date:** [April 26, 2024, 9:21am UTC](https://community.openfn.org/t/write-better-jobs-with-the-lazy-state-operator/432/1 "2024-04-26T09:21:09Z")

</div>

Hi Community!

I’m really excited to share a shiny new thing with you: The Lazy State Operator!

```auto
get($.data.url)

```

In a nutshell, the Lazy State Operator (`$`) provides an easier, neater way to reference properties on state. It can make your job code way more elegant.

It means you don’t have to wrap your state paths in `dataValue()` or arrow functions.

Here’s how you might use it in your code:

```auto
post('/patients', $.data.newPatient)

```

`$` is the Lazy State Operator, and it means “Read this path from state _just before_ this operation runs”. Its exactly equivalent to doing this:

```auto
post('/patients', (state) => state.data.newPatient)

```

In fact, you can think of `$` as an alias for `(state) => state`. If you can pass a function, you can use lazy state instead.

You can use the lazy state operator in basically any expression, so long as it’s going into the argument of an operation. You can nest it in an object:

```auto
post('www', {
    type: 'patient',
    name: $.data.patient.name,
    address: $.data.patient.address,
})

```

Or use it in a template literal:

```auto
create({
  name: `${$.patients[0].first_name} ${$.patients[0].last_name}`
});

```

You can read more full documentation here at [docs.openfn.org](https://docs.openfn.org/documentation/jobs/job-writing-guide#the-lazy-state-operator)

The Lazy State Operator is new and experimental. We stealth released it a couple of weeks ago so that the team could try it out internally, then we fixed a few things that weren’t working. And now we’re looking from feedback from our community!

Try The Lazy State operator for yourself and let us know if it works well for you! Or, if it doesn’t work, we’d love to hear that too!

Thanks, and happy coding!

-Joe
