Skip to content

Commit

Permalink
Rename condition to ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbforlife committed Jan 9, 2024
1 parent 8a03a2c commit 8f5e2ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@

## Package Examples

### `truthy/condition`
```go
// Ever wish Go had ? : ternary operators?
// Now it has a ternary function.
x := condition.Evaluate(is.Truthy(""), 1, 10) // x == 10

// condition.Evaluate cannot lazily evaluate its arguments,
// but you can use a closure to fake it.
s := condition.Evaluate(is.TruthySlice([]string{""}),
func() string {
// do some calculation
return "foo"
},
func() string {
// do some calculation
return "bar"
})()
// s == "foo"
```

### `truthy/defaults`
```go
// How about an equivalent of the nullish coalescing operator ??
Expand Down Expand Up @@ -101,3 +81,23 @@ newptr := pointers.New("meaning of life") // makes a pointer to a string, wow!
// pointers.First returns the first pointer that isn't nil.
strptr = pointers.First(strptr, newptr) // returns newptr
```

### `truthy/ternary`
```go
// Ever wish Go had ? : ternary operators?
// Now it has a ternary function.
x := ternary.Evaluate(is.Truthy(""), 1, 10) // x == 10

// ternary.Evaluate cannot lazily evaluate its arguments,
// but you can use a closure to fake it.
s := ternary.Evaluate(is.TruthySlice([]string{""}),
func() string {
// do some calculation
return "foo"
},
func() string {
// do some calculation
return "bar"
})()
// s == "foo"
```
2 changes: 1 addition & 1 deletion condition/condition.go → ternary/ternary.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package condition
package ternary

// Evaluate returns ifVal if cond is true,
// otherwise it returns elseVal.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package condition_test
package ternary_test

import (
"fmt"

"github.com/carlmjohnson/truthy/condition"
"github.com/carlmjohnson/truthy/is"
"github.com/carlmjohnson/truthy/ternary"
)

func ExampleEvaluate_lazy() {
i := 1
// Cond cannot lazily evaluate its arguments,
// but you can use a closure to fake it.
s := condition.Evaluate(
s := ternary.Evaluate(
is.Truthy(i),
func() string {
// do some calculation
Expand Down

0 comments on commit 8f5e2ee

Please sign in to comment.