opt.Optional[T]
							parent
							
								
									e86446ff5b
								
							
						
					
					
						commit
						9cbd049b34
					
				
							
								
								
									
										37
									
								
								README.md
								
								
								
								
							
							
						
						
									
										37
									
								
								README.md
								
								
								
								
							|  | @ -9,3 +9,40 @@ In other programming languages, an **optional-type** might be know as: a **optio | ||||||
| Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-opt | Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-opt | ||||||
| 
 | 
 | ||||||
| [](https://godoc.org/github.com/reiver/go-opt) | [](https://godoc.org/github.com/reiver/go-opt) | ||||||
|  | 
 | ||||||
|  | ## Examples | ||||||
|  | 
 | ||||||
|  | Here is an example **optional-type** that can hold a string: | ||||||
|  | ```go | ||||||
|  | var op opt.Optional[string] // the default value is nothing. | ||||||
|  | 
 | ||||||
|  | // ... | ||||||
|  | 
 | ||||||
|  | if opt.Nothing[string]() == op { | ||||||
|  | 	fmt.Println("nothing") | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // ... | ||||||
|  | 
 | ||||||
|  | switch op { | ||||||
|  | case op.Nothing[string](): | ||||||
|  | 	//@TODO | ||||||
|  | case op.Something("apple"): | ||||||
|  | 	//@TODO | ||||||
|  | case op.Something("banana"): | ||||||
|  | 	//@TODO | ||||||
|  | case op.Something("cherry"): | ||||||
|  | 	//@TODO | ||||||
|  | default: | ||||||
|  | 	//@TODO | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // ... | ||||||
|  | 
 | ||||||
|  | value, found := op.Get() | ||||||
|  | if { | ||||||
|  | 	fmt.Println("VALUE:", value) | ||||||
|  | } else { | ||||||
|  | 	fmt.Println("nothing") | ||||||
|  | } | ||||||
|  | ``` | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue