|
2510 | 2510 | "test_eq(L((2,1),(1,3),(3,2)).rstarargwhere(lt, negate=True), [1])" |
2511 | 2511 | ] |
2512 | 2512 | }, |
| 2513 | + { |
| 2514 | + "cell_type": "code", |
| 2515 | + "execution_count": null, |
| 2516 | + "id": "541e7eab-3267-4156-8574-5cff8eb1a4e1", |
| 2517 | + "metadata": {}, |
| 2518 | + "outputs": [], |
| 2519 | + "source": [ |
| 2520 | + "#| export\n", |
| 2521 | + "@patch\n", |
| 2522 | + "@curryable\n", |
| 2523 | + "def first(self:L, f, negate=False):\n", |
| 2524 | + " \"Return first matching item\"\n", |
| 2525 | + " return first(self, f, negate)" |
| 2526 | + ] |
| 2527 | + }, |
| 2528 | + { |
| 2529 | + "cell_type": "code", |
| 2530 | + "execution_count": null, |
| 2531 | + "id": "966ffa22-7599-4ee8-ac54-d89eedda339e", |
| 2532 | + "metadata": {}, |
| 2533 | + "outputs": [], |
| 2534 | + "source": [ |
| 2535 | + "test_eq(t.first(lambda o:o>4), 99)\n", |
| 2536 | + "test_eq(t.first(lambda o:o>4,negate=True), 0)" |
| 2537 | + ] |
| 2538 | + }, |
| 2539 | + { |
| 2540 | + "cell_type": "code", |
| 2541 | + "execution_count": null, |
| 2542 | + "id": "1664acc6-45a4-4b00-aa20-e1bcc6e2a578", |
| 2543 | + "metadata": {}, |
| 2544 | + "outputs": [ |
| 2545 | + { |
| 2546 | + "data": { |
| 2547 | + "text/plain": [ |
| 2548 | + "[8, 9, None]" |
| 2549 | + ] |
| 2550 | + }, |
| 2551 | + "execution_count": null, |
| 2552 | + "metadata": {}, |
| 2553 | + "output_type": "execute_result" |
| 2554 | + } |
| 2555 | + ], |
| 2556 | + "source": [ |
| 2557 | + "nested = L([[1,2,8,4], [5,9,7], [1,1,1]])\n", |
| 2558 | + "nested.map(L.first(gt(5)))" |
| 2559 | + ] |
| 2560 | + }, |
| 2561 | + { |
| 2562 | + "cell_type": "code", |
| 2563 | + "execution_count": null, |
| 2564 | + "id": "6fde986b-8d9b-469a-af0e-ebba11917375", |
| 2565 | + "metadata": {}, |
| 2566 | + "outputs": [], |
| 2567 | + "source": [ |
| 2568 | + "#| export\n", |
| 2569 | + "@patch\n", |
| 2570 | + "@curryable\n", |
| 2571 | + "def last(self:L, f, negate=False):\n", |
| 2572 | + " \"Return last matching item\"\n", |
| 2573 | + " return last(self, f, negate)" |
| 2574 | + ] |
| 2575 | + }, |
| 2576 | + { |
| 2577 | + "cell_type": "code", |
| 2578 | + "execution_count": null, |
| 2579 | + "id": "6f2a7f52-c50b-4c98-a0d5-db300b3c7fb2", |
| 2580 | + "metadata": {}, |
| 2581 | + "outputs": [], |
| 2582 | + "source": [ |
| 2583 | + "test_eq(L(5,4,3,2,99,1).last(lambda o:o>4), 99)\n", |
| 2584 | + "test_eq(L(5,4,3,2,99,1).last(lambda o:o>4,negate=True), 1)" |
| 2585 | + ] |
| 2586 | + }, |
| 2587 | + { |
| 2588 | + "cell_type": "code", |
| 2589 | + "execution_count": null, |
| 2590 | + "id": "555824ef-b4b9-45eb-8e1e-24ded3490f1f", |
| 2591 | + "metadata": {}, |
| 2592 | + "outputs": [ |
| 2593 | + { |
| 2594 | + "data": { |
| 2595 | + "text/plain": [ |
| 2596 | + "[8, 7, None]" |
| 2597 | + ] |
| 2598 | + }, |
| 2599 | + "execution_count": null, |
| 2600 | + "metadata": {}, |
| 2601 | + "output_type": "execute_result" |
| 2602 | + } |
| 2603 | + ], |
| 2604 | + "source": [ |
| 2605 | + "nested = L([[1,2,8,4], [5,9,7], [1,1,1]])\n", |
| 2606 | + "nested.map(L.last(gt(5)))" |
| 2607 | + ] |
| 2608 | + }, |
2513 | 2609 | { |
2514 | 2610 | "cell_type": "code", |
2515 | 2611 | "execution_count": null, |
|
0 commit comments