From aa5578ffe8fb2a9e6d24b0077f5d7ced630b7dfa Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 21 Apr 2025 14:54:23 -0400 Subject: Rename List.first() to List.where() --- api/lists.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'api/lists.md') diff --git a/api/lists.md b/api/lists.md index 727aa077..32433bee 100644 --- a/api/lists.md +++ b/api/lists.md @@ -118,30 +118,6 @@ target | `T` | The item to search for. | - >> [10, 20, 30, 40, 50].find(9999) = none : Int? -``` -## List.first - -```tomo -List.first : func(list: [T], predicate: func(item:&T -> Bool) -> Int) -``` - -Find the index of the first item that matches a predicate function (if any). - -Argument | Type | Description | Default ----------|------|-------------|--------- -list | `[T]` | The list to search through. | - -predicate | `func(item:&T -> Bool)` | A function that returns `yes` if the item should be returned or `no` if it should not. | - - -**Return:** Returns the index of the first item where the predicate is true or `!Int` if no item matches. - - -**Example:** -```tomo ->> [4, 5, 6].find(func(i:&Int): i.is_prime()) -= 5 : Int? ->> [4, 6, 8].find(func(i:&Int): i.is_prime()) -= none : Int? - ``` ## List.from @@ -649,3 +625,27 @@ list | `[T]` | The list to process. | - = {10, 20, 30} ``` +## List.where + +```tomo +List.where : func(list: [T], predicate: func(item:&T -> Bool) -> Int) +``` + +Find the index of the first item that matches a predicate function (if any). + +Argument | Type | Description | Default +---------|------|-------------|--------- +list | `[T]` | The list to search through. | - +predicate | `func(item:&T -> Bool)` | A function that returns `yes` if the item's index should be returned or `no` if it should not. | - + +**Return:** Returns the index of the first item where the predicate is true or `!Int` if no item matches. + + +**Example:** +```tomo +>> [4, 5, 6].where(func(i:&Int): i.is_prime()) += 5 : Int? +>> [4, 6, 8].find(func(i:&Int): i.is_prime()) += none : Int? + +``` -- cgit v1.2.3