typestar

Pipes in Julia

|> feeds left to right; dotted pipes broadcast the chain.

targets = ["m42", "  m31 ", "M13", "m45  "]

# |> feeds a value to the next function, left to right.
cleaned = targets .|> strip .|> uppercase
println(cleaned)

count_bright = cleaned |> unique |> length
println("$count_bright unique targets")

# Compose with \circ-free syntax: a small chain of named steps.
normalize(s) = uppercase(strip(s))
label(s) = "NGC queue: $s"
println("  m57 " |> normalize |> label)

How it works

  1. targets .|> strip .|> uppercase cleans every element.
  2. cleaned |> unique |> length reads as a sentence.
  3. Small named steps keep chains debuggable.

The run, in numbers

Lines
13
Characters to type
410
Tokens
77
Three-star pace
65 tpm

At the three-star pace of 65 tokens a minute, this run takes about 71 seconds.

Type this snippet

Step 1 of 3 in Idioms, step 19 of 27 in Language basics.

← Previous Next →