3 ms·
What’s the difference? stdin |> byLine(yes) |> uniq |> map(a => aidup) |> array |> sort |> copy(stdout) I’m sorry if y
by vips7L 1y ago
What’s the difference?
stdin
|> byLine(yes)
|> uniq
|> map(a => aidup)
|> array
|> sort
|> copy(stdout)
I’m sorry if you took it as bashing. It’s mere curiosity as I’ve never seen that preference before.
- johnisgood 1y agoIs it a fair comparison? Would it work in Elixir? I have not seen it in Elixir projects as such.
- Jtsummers 1y agoAdjusting for the actual Elixir functions, yes that would work. That's how Elixir's |> works, it takes the value from the left and passes it as the first argument to function on the right. Which is what the chain of calls in D is doing.
- vips7L 1y agoThanks. I don’t know elixir.
- johnisgood 1y agoI have not yet seen such long chains in Elixir. Could you show me a project where it is used? "map(a => aidup)" caught me by surprise, too. Would Elixir do such a thing?
- deleted 1y ago[deleted]
- johnisgood 1y agoFor what it's worth, in Elixir you might write something along the lines of the following (this is a rough translation, I haven't tested it): IO.stream(:stdio, :line) |> Stream.map(&String.trim_trailing/1) |> Enum.uniq() |> Enum.map(&String.duplicate(&1, 1)) |> Enum.sort() |> Enum.each(&IO.puts/1) This is not equivalent in style or presentation to: stdin .byLine(KeepTerminator.yes) .uniq .map!(a => a.idup) .array .sort .copy(stdout.lockingTextWriter()); Personally, I find the D version visually unappealing (and confusing), especially the way "stdin" sits alone on its own line, followed by a sequence of indented method calls. The excessive use of dots combined with the indentation structure makes it look, to me, rather awkward. That is just my own opinion.
- WalterBright 1y agoYou can format it whatever way you like. D does not use formatting to impose semantic meaning.