Skip to content

Commit ad52906

Browse files
authored
docs: change <> to [] in docs.md (#16632)
1 parent 7c02274 commit ad52906

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/docs.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,7 +3747,7 @@ fn main() {
37473747

37483748
```v wip
37493749
3750-
struct Repo<T> {
3750+
struct Repo[T] {
37513751
db DB
37523752
}
37533753
@@ -3763,14 +3763,14 @@ struct Post {
37633763
body string
37643764
}
37653765
3766-
fn new_repo<T>(db DB) Repo<T> {
3767-
return Repo<T>{db: db}
3766+
fn new_repo[T](db DB) Repo[T] {
3767+
return Repo[T]{db: db}
37683768
}
37693769
37703770
// This is a generic function. V will generate it for every type it's used with.
3771-
fn (r Repo<T>) find_by_id(id int) ?T {
3771+
fn (r Repo[T]) find_by_id(id int) ?T {
37723772
table_name := T.name // in this example getting the name of the type gives us the table name
3773-
return r.db.query_one<T>('select * from ${table_name} where id = ?', id)
3773+
return r.db.query_one[T]('select * from ${table_name} where id = ?', id)
37743774
}
37753775
37763776
db := new_db()
@@ -3782,7 +3782,7 @@ post := posts_repo.find_by_id(1)? // find_by_id<Post>
37823782

37833783
Currently generic function definitions must declare their type parameters, but in
37843784
future V will infer generic type parameters from single-letter type names in
3785-
runtime parameter types. This is why `find_by_id` can omit `<T>`, because the
3785+
runtime parameter types. This is why `find_by_id` can omit `[T]`, because the
37863786
receiver argument `r` uses a generic type `T`.
37873787

37883788
Another example:

0 commit comments

Comments
 (0)