liveBook · Manning

Join

As explained in Julia as a Second Language

join is a Julia function that combines iterable elements with a separator or writes the resulting text to an I/O object.

Julia’s join combines the elements of any iterable into text. Without a separator, it concatenates values directly; with one, it places that separator between elements. section 4.8 section 11.2.1

Useful forms include:

  • join(['H', 'E', 'L', 'L', 'O']) returns "HELLO". section 4.8
  • join('A':2:'G') returns "ACEG", showing that ranges are valid iterables. section 4.8
  • join(words, '_') combines collected words with underscores, turning separated camel-case words into snake case. section 11.2.1
  • join(io, row, ',') writes comma-separated values directly to an I/O object instead of returning a string. section 17.4.2

Create a snake-case name

Collect the words from a camel-case string, lowercase them, and join them with an underscore: `words = ["one", "Two", "Three", "Four"]`; `join(lowercase.(words), '_')` produces `"one_two_three_four"`. section 11.2.1

Listing 17.5 An io.jl file with added save_engines code
function save_engines(path::AbstractString, engines)
   open(path, "w") do io
       println(io, "name,company,mass,thrust,Isp")
       for (name, egn) in engines
           row = [name, "", egn.mass, egn.thrust, egn.Isp]
           join(io, row, ',')
           println(io)
       end
   end
end

Inspect a practical file-writing utility that uses join to serialize rocket-engine rows as comma-separated data. section 17.4.2

How Julia as a Second Language covers it

How deep it goes
Explains direct concatenation, separators, iterable ranges, string transformation, and I/O output through runnable examples.
Examples
Uses character arrays, character ranges, camel-case words, CSV rows, standard output, and rocket-engine data.
What it assumes
Assumes familiarity with for-loop iteration, characters, strings, arrays, ranges, and basic I/O objects.
What you can do after
Apply join to concatenate iterable values, insert separators, or emit formatted rows to an I/O destination.
How it connects
Connects join with strings, characters, iterables, ranges, camel-case conversion, snake case, and I/O.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.