doc: another generics example (#6031)
							parent
							
								
									0fb8074353
								
							
						
					
					
						commit
						2c6286b381
					
				
							
								
								
									
										26
									
								
								doc/docs.md
								
								
								
								
							
							
						
						
									
										26
									
								
								doc/docs.md
								
								
								
								
							| 
						 | 
				
			
			@ -1651,6 +1651,32 @@ user := users_repo.find_by_id(1)?
 | 
			
		|||
post := posts_repo.find_by_id(1)?
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Another example:
 | 
			
		||||
```v
 | 
			
		||||
fn compare<T>(a, b T) int {
 | 
			
		||||
    if a < b {
 | 
			
		||||
        return -1
 | 
			
		||||
    }
 | 
			
		||||
    if a > b {
 | 
			
		||||
        return 1
 | 
			
		||||
    }
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
println(compare<int>(1,0)) // Outputs: 1
 | 
			
		||||
println(compare<int>(1,1)) //          0
 | 
			
		||||
println(compare<int>(1,2)) //         -1
 | 
			
		||||
 | 
			
		||||
println(compare<string>('1','0')) // Outputs: 1
 | 
			
		||||
println(compare<string>('1','1')) //          0
 | 
			
		||||
println(compare<string>('1','2')) //         -1
 | 
			
		||||
 | 
			
		||||
println(compare<float>(1.1, 1.0)) // Outputs: 1 
 | 
			
		||||
println(compare<float>(1.1, 1.1)) //          0
 | 
			
		||||
println(compare<float>(1.1, 1.2)) //         -1
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Concurrency
 | 
			
		||||
 | 
			
		||||
V's model of concurrency is very similar to Go's. To run `foo()` concurrently, just
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue