Skip to content

Instantly share code, notes, and snippets.

@cslarsen
Last active February 27, 2025 19:38
Show Gist options
  • Save cslarsen/5256744 to your computer and use it in GitHub Desktop.
Save cslarsen/5256744 to your computer and use it in GitHub Desktop.

Revisions

  1. cslarsen revised this gist Mar 27, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion heterogeneous-array.go
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    *
    /*
    * Example of heterogeneous arrayo in golang.
    *
    * The trick is simply to create an array that accepts elements that conform
  2. cslarsen created this gist Mar 27, 2013.
    25 changes: 25 additions & 0 deletions heterogeneous-array.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    *
    * Example of heterogeneous arrayo in golang.
    *
    * The trick is simply to create an array that accepts elements that conform
    * to the naked interface (an interface with no requirements).
    *
    * Expected output:
    *
    * $ go run array.go
    * [1 2 3.14 hey {10 20}]
    *
    */
    package main

    import "fmt"

    type foo struct {
    a int
    b int
    }

    func main() {
    a := []interface{}{1, 2, 3.14, "hey", foo{10, 20}}
    fmt.Println(a)
    }