Manipulate string from File Stream in Elixir -


i new elixir. trying take text file turn graph.

the file formatted such:

1 2 1 3 2 3 

each number being id of connected nodes.

how can take 2 values string.split/1 function somewhere else in program ? had far:

file.stream!("../text_file")     |> stream.map( &(string.replace(&1, "\n", "")))     |> enum.each(string.split/1) 

it output :ok atom, print content if swap string.split/1 io.puts/1

enum.each/2 meant used functions don't care return value (usually functions side effects, io.puts). if want collect returned data, need enum.map/2. also, if want delete trailing whitespace, should use string.trim_trailing/1)

file.stream!("a")  |> stream.map(&string.trim_trailing/1) |> enum.map(&string.split/1) |> io.inspect 

output:

[["1", "2"], ["1", "3"], ["2", "3"]] 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -