catala/tests/test_array/good/fold.catala_en
2023-04-12 11:38:12 +02:00

46 lines
1.1 KiB
Plaintext

## Article
```catala
declaration structure S:
data id content integer
data income content money
declaration scope A:
context output x content collection S
scope A:
definition x equals [
S { -- id: 0 -- income: $0 };
S { -- id: 1 -- income: $4 + $5 };
S { -- id: 2 -- income: $8 * 0.65 }
]
declaration scope B:
a scope A
output argmax content S
output argmin content S
scope B:
definition argmax equals
(m among a.x such that m.income * 2.0 is maximum
or if collection empty then S { -- id: -1 --income: $0 })
definition argmin equals
(m among a.x such that m.income + $5 is minimum
or if collection empty then S { -- id: -1 --income: $20 })
```
```catala-test-inline
$ catala Interpret -s A
[RESULT] Computation successful! Results:
[RESULT] x =
[S { "id"= 0; "income"= $0.00 }; S { "id"= 1; "income"= $9.00 };
S { "id"= 2; "income"= $5.20 }]
```
```catala-test-inline
$ catala Interpret -s B
[RESULT] Computation successful! Results:
[RESULT] argmax = S { "id"= 1; "income"= $9.00 }
[RESULT] argmin = S { "id"= 0; "income"= $0.00 }
```