Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d28253d
add p/demo/ternary
grepsuzette Jul 9, 2024
6b42940
feat(examples): add stateless r/demo/games/tictactoe 1P-VS-CPU
grepsuzette Jul 9, 2024
0dca9cb
typo
grepsuzette Jul 9, 2024
35dc9f8
minor
grepsuzette Jul 10, 2024
fc26365
more responsive (use css flex)
grepsuzette Jul 12, 2024
606af47
last minute addendum
grepsuzette Jul 12, 2024
68e8dde
Merge branch 'master' into tictactoe
grepsuzette Aug 23, 2024
ee549ed
remove submodule gfx
grepsuzette Aug 23, 2024
83333f6
lint
grepsuzette Aug 23, 2024
450037a
Merge remote-tracking branch 'refs/remotes/grepsuzette/tictactoe' int…
grepsuzette Aug 23, 2024
49e76b5
delete useless
grepsuzette Aug 23, 2024
5b12a63
run make fmt
grepsuzette Aug 23, 2024
f5735c9
gno mod tidy
grepsuzette Aug 23, 2024
8041c7c
tidy
grepsuzette Aug 23, 2024
748b84f
tidy
grepsuzette Aug 23, 2024
b193c4e
itidy
grepsuzette Aug 23, 2024
9b47e88
Merge branch 'master' into tictactoe
grepsuzette Aug 26, 2024
8f7fbd9
add r/games/shifumi to the list of games
grepsuzette Sep 1, 2024
412616e
Merge remote-tracking branch 'refs/remotes/grepsuzette/tictactoe' int…
grepsuzette Sep 1, 2024
21c00cf
type
grepsuzette Sep 5, 2024
a162ef2
Merge branch 'master' into tictactoe
thehowl Jan 16, 2025
2ec9d50
fix gno.mod for tests to pass
grepsuzette Jan 19, 2025
f195beb
fix lint problem
grepsuzette Jan 19, 2025
455bc22
mod
grepsuzette Jan 19, 2025
11f1a95
move files from /[rp]/demo to /[rp]/grepsuzette
grepsuzette Jan 21, 2025
5643b7c
more
grepsuzette Jan 21, 2025
2dba381
more
grepsuzette Jan 21, 2025
2f9e850
index
grepsuzette Jan 21, 2025
f1d211b
r/grepsuzette/querystring
grepsuzette Jan 21, 2025
071ab29
ok, tested with `gnodev -web-html`
grepsuzette Jan 22, 2025
b22c80d
more
grepsuzette Jan 22, 2025
1e1f9ad
Merge branch 'master' into tictactoe
grepsuzette Jan 23, 2025
ebae8fa
Merge branch 'master' into tictactoe
thehowl Sep 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/gno.land/p/demo/ternary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Ternary package

Ternary operator have notoriously been absent from Go
from its inception.

This package proposes ternary functions.

We don't advocate for their systematic use, but
it can often prove useful when realms need to generate
Markdown,

## Usage
```go
import "p/demo/ternary"

func Render(path string) string {
// display appropriate greeting
return "# " + ternary.String(isEarly, "hi", "bye")
}
```

Another example:

`f := ternary.Float64(useGoldenRatio, 1.618, 1.66)`

## List of functions

Most native types got a function.

Note: both branches yes/no get evaluated, contrarily to the C operator.
Please don't use this if your branches are expensive.

Functions:

* func String(cond bool, yes, no string) string
* func Int(cond bool, yes, no int) int
* func Int8(cond bool, yes, no int8) int8
* func Int16(cond bool, yes, no int16) int16
* func Int32(cond bool, yes, no int32) int32
* func Int64(cond bool, yes, no int64) int64
* func Uint(cond bool, yes, no uint) uint
* func Uint8(cond bool, yes, no uint8) uint8
* func Uint16(cond bool, yes, no uint16) uint16
* func Uint32(cond bool, yes, no uint32) uint32
* func Uint64(cond bool, yes, no uint64) uint64
* func Float32(cond bool, yes, no float32) float32
* func Float64(cond bool, yes, no float64) float64
* func Rune(cond bool, yes, no rune) rune
* func Bool(cond bool, yes, no bool) rune
* func Address(cond bool, std.Address, std.Address) std.Address

1 change: 1 addition & 0 deletions examples/gno.land/p/demo/ternary/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/ternary
115 changes: 115 additions & 0 deletions examples/gno.land/p/demo/ternary/ternary.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package ternary

import "std"

func String(cond bool, yes, no string) string {
if cond {
return yes
}
return no
}

func Int(cond bool, yes, no int) int {
if cond {
return yes
}
return no
}

func Int8(cond bool, yes, no int8) int8 {
if cond {
return yes
}
return no
}

func Int16(cond bool, yes, no int16) int16 {
if cond {
return yes
}
return no
}

func Int32(cond bool, yes, no int32) int32 {
if cond {
return yes
}
return no
}

func Int64(cond bool, yes, no int64) int64 {
if cond {
return yes
}
return no
}

func Uint(cond bool, yes, no uint) uint {
if cond {
return yes
}
return no
}

func Uint8(cond bool, yes, no uint8) uint8 {
if cond {
return yes
}
return no
}

func Uint16(cond bool, yes, no uint16) uint16 {
if cond {
return yes
}
return no
}

func Uint32(cond bool, yes, no uint32) uint32 {
if cond {
return yes
}
return no
}

func Uint64(cond bool, yes, no uint64) uint64 {
if cond {
return yes
}
return no
}

func Float32(cond bool, yes, no float32) float32 {
if cond {
return yes
}
return no
}

func Float64(cond bool, yes, no float64) float64 {
if cond {
return yes
}
return no
}

func Rune(cond bool, yes, no rune) rune {
if cond {
return yes
}
return no
}

func Bool(cond bool, yes, no bool) bool {
if cond {
return yes
}
return no
}

func Address(cond bool, yes, no std.Address) std.Address {
if cond {
return yes
}
return no
}
48 changes: 48 additions & 0 deletions examples/gno.land/p/demo/ternary/ternary_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ternary

import (
"std"
"testing"
)

func TestTernary(t *testing.T) {
assert(t, String(true, "a", "b") == "a")
assert(t, String(false, "a", "b") == "b")
assert(t, Int(true, 0, 1) == 0)
assert(t, Int(false, 0, 1) == 1)
assert(t, Int8(true, 0, 1) == 0)
assert(t, Int8(false, 0, 1) == 1)
assert(t, Int16(true, 0, 1) == 0)
assert(t, Int16(false, 0, 1) == 1)
assert(t, Int32(true, 0, 1) == 0)
assert(t, Int32(false, 0, 1) == 1)
assert(t, Int64(true, 0, 1) == 0)
assert(t, Int64(false, 0, 1) == 1)
assert(t, Uint(true, 0, 1) == 0)
assert(t, Uint(false, 0, 1) == 1)
assert(t, Uint8(true, 0, 1) == 0)
assert(t, Uint8(false, 0, 1) == 1)
assert(t, Uint16(true, 0, 1) == 0)
assert(t, Uint16(false, 0, 1) == 1)
assert(t, Uint32(true, 0, 1) == 0)
assert(t, Uint32(false, 0, 1) == 1)
assert(t, Uint64(true, 0, 1) == 0)
assert(t, Uint64(false, 0, 1) == 1)
assert(t, Float32(true, 3.14, 1.618) == 3.14)
assert(t, Float32(false, 3.14, 1.618) == 1.618)
assert(t, Float64(true, 3.14, 1.618) == 3.14)
assert(t, Float64(false, 3.14, 1.618) == 1.618)
assert(t, Rune(true, '是', '否') == '是')
assert(t, Rune(false, '是', '否') == '否')
n := 17
assert(t, !Bool(true, n%2 == 0, n < 10))
assert(t, Address(true, std.Address("g0"), std.Address("g1")).String() == "g0")
assert(t, Address(false, std.Address("g0"), std.Address("g1")).String() == "g1")
}

func assert(t *testing.T, val bool) {
t.Helper()
if !val {
t.Errorf("expected true, got false")
}
}
Loading
Loading