| 2265 | |
| 2266 | |
| 2267 | def test_flatMap_self_pymethod(): |
| 2268 | items = ['Four', 'Three', 'One'] |
| 2269 | |
| 2270 | class Counter: |
| 2271 | def __init__(self): |
| 2272 | self.count = 0 |
| 2273 | |
| 2274 | def increment(self, element, index, array): |
| 2275 | self.count += 1 |
| 2276 | |
| 2277 | obj = Counter() |
| 2278 | assert obj.count == 0 |
| 2279 | result = pm.eval(""" |
| 2280 | (arr, increment, result) => { |
| 2281 | let jsObj = {count: 0} |
| 2282 | arr.flatMap(increment, jsObj); |
| 2283 | return jsObj.count; |
| 2284 | } |
| 2285 | """)(items, obj.increment) |
| 2286 | assert obj.count == 0 |
| 2287 | assert result == 3 |
| 2288 | |
| 2289 | |
| 2290 | def test_flatMap_self_pyfunction(): |