From 5f22e5ebecbcde5178d3ed88515feb6a06b6002e Mon Sep 17 00:00:00 2001 From: mileusna Date: Mon, 17 Jul 2017 21:13:32 +0200 Subject: [PATCH] Update documentation --- README.md | 8 +++++--- doc.go | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2d3d75d..f903e83 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ if x==y { val = "Value OK" } ``` -or if you prefere more readable and longer version +or if you prefere perhapse more readable but longer version ```Go var val string @@ -28,12 +28,12 @@ if x==y { } ``` -This is where conditional package steps in. It provides fuctions that replaces ternary operator for each basic type in go. We can now write conditional assignment in only one go line: +This is where conditional package steps in. It provides fuctions that replaces ternary operator for each basic type in go. We can now write conditional assignment in only one Go line: ```Go val := conditional.String(x==y, "Value OK", "Value not OK") ``` -Package conditional also provides fuctions for all go basic types +Package conditional also provides fuctions for all Go basic types ```Go n := conditional.Int(x==y, 20, 0) u := conditional.UInt(true, 23, 15) @@ -53,6 +53,8 @@ import ( ) func main() { + x := 2 + y := 3 fmt.Println(conditional.Int(x==y, 20, 0)) fmt.Println(conditional.String(x==y, "Value OK", "Value not OK")) fmt.Println(conditional.UInt(true, 23, 15)) diff --git a/doc.go b/doc.go index ef4d19f..e6509c7 100644 --- a/doc.go +++ b/doc.go @@ -5,14 +5,14 @@ Many languages have ternary operator which makes it easy and short to assign val val := (x==y) ? "Value OK" : "Value not OK" -Unfortunately, Go doesn't have ternary operator so the shortest way to write this code in go would be +Unfortunately, Go doesn't have ternary operator so the shortest way to write this code in Go would be val := "Value not OK" if x==y { val = "Value OK" } -or if you prefere more readable and longer version +or if you prefere perhapse more readable but longer version var val string if x==y { @@ -21,13 +21,20 @@ or if you prefere more readable and longer version val = "Value not OK" } -This is where conditional package steps in. It provides fuctions that replace ternary operator for each type in go +This is where conditional package steps in. It provides fuctions that replaces ternary operator for each basic type in Go - i := conditional.Int(x==y, 20, 0) + // previouse example, now in only one line s := conditional.String(x==y, "Value OK", "Value not OK") + + // for other basic Go types + n := conditional.Int(x==y, 20, 0) u := conditional.UInt(true, 23, 15) + f := conditional.Float64(true, 23.1, 15.7) // etc. etc. + // even for interface{} + i := conditional.Interface(x==y, "Great", 10) + Example: package main @@ -38,6 +45,8 @@ Example: ) func main() { + x := 2 + y := 3 fmt.Println(conditional.Int(x==y, 20, 0)) fmt.Println(conditional.String(x==y, "Value OK", "Value not OK")) fmt.Println(conditional.UInt(true, 23, 15))