aboutsummaryrefslogtreecommitdiff
path: root/man/man3/tomo-List.first.3
blob: a8183cc8f0353706c5bb15fca6da54b626635b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'\" t
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
.TH List.first 3 2025-04-21T14:44:34.258746 "Tomo man-pages"
.SH NAME
List.first \- find an index where a predicate matches
.SH LIBRARY
Tomo Standard Library
.SH SYNOPSIS
.nf
.BI List.first\ :\ func(list:\ [T],\ predicate:\ func(item:&T\ ->\ Bool)\ ->\ Int)
.fi
.SH DESCRIPTION
Find the index of the first item that matches a predicate function (if any).


.SH ARGUMENTS

.TS
allbox;
lb lb lbx lb
l l l l.
Name	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. 	-
.TE
.SH RETURN
Returns the index of the first item where the predicate is true or `!Int` if no item matches.

.SH EXAMPLES
.EX
>> [4, 5, 6].find(func(i:&Int): i.is_prime())
= 5 : Int?
>> [4, 6, 8].find(func(i:&Int): i.is_prime())
= none : Int?
.EE