Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mileusna committed Jul 17, 2017
1 parent dc67e89 commit 5f22e5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))
Expand Down
17 changes: 13 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 5f22e5e

Please sign in to comment.