Skip to content

Instantly share code, notes, and snippets.

@Patrikios
Last active September 19, 2022 13:12
Show Gist options
  • Select an option

  • Save Patrikios/e85736caef18f5ebd52fc43c5d382b71 to your computer and use it in GitHub Desktop.

Select an option

Save Patrikios/e85736caef18f5ebd52fc43c5d382b71 to your computer and use it in GitHub Desktop.

Revisions

  1. Patrikios revised this gist Sep 19, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions pairs_study.jl
    Original file line number Diff line number Diff line change
    @@ -24,5 +24,8 @@ r2 = [r.first, r.second]
    uppercase(r2)
    # ERROR
    uppercase.(r2)
    # 2-element Vector{String}:
    # "PAT"
    # "MAT"
    uppercase(r)
    # ERROR
  2. Patrikios revised this gist Sep 19, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions pairs_study.jl
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,8 @@ p = "foo" => 7
    for x in p
    println(x)
    end
    # foo
    # 7
    # but a Pair is treated as a single "scalar" for broadcasting operations
    r = "Pat" => "Mat"
    r2 = [r.first, r.second]
  3. Patrikios created this gist Sep 19, 2022.
    26 changes: 26 additions & 0 deletions pairs_study.jl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    a_tuple = (1, 2)
    a_pair = 1 => 2
    a_tuple != a_pair
    # true
    # The elements are stored in the fields first and second
    a_pair.first
    # 1
    a_pair.second
    # 1
    typeof(a_pair)
    # Pair{Int64, Int64}
    # construct pair with 'Pair' keyword
    Pair(1, 32.1)
    # They can also be accessed via iteration
    p = "foo" => 7
    for x in p
    println(x)
    end
    # but a Pair is treated as a single "scalar" for broadcasting operations
    r = "Pat" => "Mat"
    r2 = [r.first, r.second]
    uppercase(r2)
    # ERROR
    uppercase.(r2)
    uppercase(r)
    # ERROR