Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion exercises/concept/airport-robot/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ It only needs to have all the necessary methods defined.

There is one very special interface type in Go, the **empty interface** type that contains zero methods.
The empty interface is written like this: `interface{}`.
In Go 1.18 or higher, `any` can be used as well. It was defined as an alias.
Since Go 1.18, `any` is an alias for `interface{}`, and is more commonly used.

Since the empty interface has no methods, every type implements it implicitly.
This is helpful for defining a function that can generically accept any value.
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/sorting-room/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NOTE: we should use the `ExtractFancyNumber` function!

## 5. Implement `DescribeAnything` which uses them all

This is the main function Jen needs which takes any input (the empty interface means any value at all: `interface{}`).
This is the main function Jen needs which takes any input.
`DescribeAnything` should delegate to the other functions based on the type of the value passed in.
More specifically:

Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/sorting-room/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A type assertion allows us to extract the interface value's underlying concrete
For example:

```go
var input interface{} = 12
var input any = 12
number := input.(int)
```

Expand All @@ -57,7 +57,7 @@ It has the same syntax as a type assertion (`interfaceVariable.(concreteType)`),
Here is an example:

```go
var i interface{} = 12 // try: 12.3, true, int64(12), []int{}, map[string]int{}
var i any = 12 // try: 12.3, true, int64(12), []int{}, map[string]int{}

switch v := i.(type) {
case int:
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/sorting-room/.meta/exemplar.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func DescribeFancyNumberBox(fnb FancyNumberBox) string {
}

// DescribeAnything should return a string describing whatever it contains.
func DescribeAnything(i interface{}) string {
func DescribeAnything(i any) string {
switch v := i.(type) {
case int:
return DescribeNumber(float64(v))
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/sorting-room/sorting_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func DescribeFancyNumberBox(fnb FancyNumberBox) string {
}

// DescribeAnything should return a string describing whatever it contains.
func DescribeAnything(i interface{}) string {
func DescribeAnything(i any) string {
panic("Please implement DescribeAnything")
}
2 changes: 1 addition & 1 deletion exercises/concept/sorting-room/sorting_room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestDescribeFancyNumberBox(t *testing.T) {
func TestDescribeAnything(t *testing.T) {
tests := []struct {
description string
input interface{}
input any
want string
}{
{
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"abbreviate": &[]testCase{},
}
if err := gen.Gen("acronym", j, t); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/all-your-base/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"rebase": &[]testCase{},
}
if err := gen.Gen("all-your-base", j, t); err != nil {
Expand All @@ -26,11 +26,11 @@ type testCase struct {
Digits []int `json:"digits"`
OutputBase int `json:"outputBase"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

func (o testCase) Result() []int {
s, ok := o.Expected.([]interface{})
s, ok := o.Expected.([]any)
if !ok {
return nil
}
Expand All @@ -43,7 +43,7 @@ func (o testCase) Result() []int {
}

func (o testCase) Err() string {
m, ok := o.Expected.(map[string]interface{})
m, ok := o.Expected.(map[string]any)
if !ok {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"allergicTo": &[]allergicToCase{},
"list": &[]listCase{},
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/alphametics/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"solve": &[]testCase{},
}
if err := gen.Gen("alphametics", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"findAnagrams": &[]testCase{},
}
if err := gen.Gen("anagram", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"isArmstrongNumber": &[]testCase{},
}
if err := gen.Gen("armstrong-numbers", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"encode": &[]testCase{},
"decode": &[]testCase{},
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/binary-search/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"find": &[]testCase{},
}
if err := gen.Gen("binary-search", j, t); err != nil {
Expand All @@ -27,7 +27,7 @@ type testCase struct {
Array []int `json:"array"`
Value int `json:"value"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

func (t testCase) Value() int {
Expand All @@ -40,7 +40,7 @@ func (t testCase) Value() int {

func (t testCase) Error() string {
if _, ok := t.Expected.(float64); !ok {
m, ok := t.Expected.(map[string]interface{})
m, ok := t.Expected.(map[string]any)
if !ok {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"response": &[]testCase{},
}
if err := gen.Gen("bob", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/book-store/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"total": &[]testCase{},
}
if err := gen.Gen("book-store", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bottle-song/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"recite": &[]testCase{},
}
if err := gen.Gen("bottle-song", j, t); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/bowling/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"roll": &[]Case{},
"score": &[]Case{},
}
Expand All @@ -26,7 +26,7 @@ type Case struct {
PreviousRolls []int `json:"previousRolls"`
Roll int `json:"roll"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

func (t Case) Score() int {
Expand All @@ -44,7 +44,7 @@ func (t Case) Valid() bool {

func (t Case) ExplainText() string {
if !t.Valid() {
m, ok := t.Expected.(map[string]interface{})
m, ok := t.Expected.(map[string]any)
if !ok {
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/change/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"findFewestCoins": &[]testCase{},
}
if err := gen.Gen("change", j, t); err != nil {
Expand All @@ -25,11 +25,11 @@ type testCase struct {
Coins []int `json:"coins"`
Target int `json:"target"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

func (t testCase) ExpectedValues() []int {
values, ok := t.Expected.([]interface{})
values, ok := t.Expected.([]any)
if !ok {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/clock/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"create": &[]defaultTestCase{},
"add": &[]defaultTestCase{},
"subtract": &[]defaultTestCase{},
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/collatz-conjecture/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"steps": &[]testCase{},
}
if err := gen.Gen("collatz-conjecture", j, t); err != nil {
Expand All @@ -24,7 +24,7 @@ type testCase struct {
Input struct {
Number int `json:"number"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

func (t testCase) ExpectedValue() int {
Expand Down
14 changes: 7 additions & 7 deletions exercises/practice/complex-numbers/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"real": &[]Case{},
"imaginary": &[]Case{},
"mul": &[]Case{},
Expand All @@ -34,11 +34,11 @@ type Case struct {
Description string `json:"description"`
Property string `json:"property"`
Input struct {
Z interface{} `json:"z"`
Z1 interface{} `json:"z1"`
Z2 interface{} `json:"z2"`
Z any `json:"z"`
Z1 any `json:"z1"`
Z2 any `json:"z2"`
} `json:"input"`
Expected interface{} `json:"expected"`
Expected any `json:"expected"`
}

type complexNumber struct {
Expand Down Expand Up @@ -88,12 +88,12 @@ func (c Case) GetExpected() complexNumber {
return getComplex(c.Expected)
}

func getComplex(in interface{}) complexNumber {
func getComplex(in any) complexNumber {
v, ok := in.(float64)
if ok {
return complexNumber{A: v}
}
s, ok := in.([]interface{})
s, ok := in.([]any)
if !ok {
panic(fmt.Sprintf("unknown value for field: %v", in))
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/connect/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"winner": &[]testCase{},
}
if err := gen.Gen("connect", j, t); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/custom-set/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"empty": &[]testCase{},
"contains": &[]testCase{},
"subset": &[]testCase{},
Expand All @@ -36,7 +36,7 @@ type testCase struct {
Set2 []int `json:"set2"` // "subset"/"disjoint"/"equal"/"difference"/"intersection"/"union" cases
Element int `json:"element"` // "contains"/"add" cases
}
Expected interface{} `json:"expected"` // bool or []int
Expected any `json:"expected"` // bool or []int
}

// There's some extra complexity because canonical-data.json uses integers, but we are using strings.
Expand Down Expand Up @@ -68,7 +68,7 @@ func (t testCase) GetExpectedBool() bool {
}

func (t testCase) GetExpectedList() []string {
v, ok := t.Expected.([]interface{})
v, ok := t.Expected.([]any)
if !ok {
log.Fatal("[ERROR] invalid type for field `expected`")
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/darts/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"score": &[]testCase{},
}
if err := gen.Gen("darts", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/diamond/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"rows": &[]testCase{},
}
if err := gen.Gen("diamond", j, t); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/dnd-character/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"modifier": &[]modifierTestCase{},
"ability": &[]emptyTestCase{},
"character": &[]emptyTestCase{},
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/dominoes/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
j := map[string]any{
"canChain": &[]testCase{},
}
if err := gen.Gen("dominoes", j, t); err != nil {
Expand Down
Loading
Loading