Skip to content

Commit 3f0e2f7

Browse files
committed
Use better example for lazy eval and explicitly explain that the value won't be recomputed each time
1 parent 2cfd023 commit 3f0e2f7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,11 +1497,27 @@ variable to only be evaluated when it is used for the first time, you can use th
14971497
`lazy` keyword:
14981498

14991499
```just
1500-
lazy password := `aws ecr get-login-password --region us-west-2`
1500+
lazy aws_account_id := `aws sts get-caller-identity --query Account --output text`
1501+
```
1502+
1503+
Once a lazy variable has been evaluated, its value is the same for the rest of
1504+
the invocation of `just`, even if it is used multiple times:
1505+
1506+
```just
1507+
lazy timestamp := `date +%s`
1508+
1509+
foo:
1510+
# The value is computed here
1511+
echo The time is {{timestamp}}
1512+
sleep 1
1513+
# The same value is used here
1514+
echo The time is still {{timestamp}}
15011515
```
15021516

15031517
This is useful for values that are expensive to compute, or that may not be
1504-
needed in every invocation of `just`.
1518+
needed in every invocation of `just`. It also saves you from having expensive
1519+
values being recomputed even for simple invocations of `just` that don't
1520+
actually use them, like `just --list`.
15051521

15061522
### Strings
15071523

0 commit comments

Comments
 (0)