SlideShare a Scribd company logo
1 of 41
Download to read offline
PIPE OPERATOR
For Ruby
@akitaonrails
Rubyconf Brasil 2016 – September 23 - 24
Rubyconf Brasil 2016 – September 23 - 24
September
23 - 24
@rubyconfbr
PIPE OPERATOR
For Ruby
@akitaonrails
Elixir Pipe
Operator
require	Integer	
1..100_000	
		|>	Stream.map(&(&1	*	3))	
		|>	Stream.filter(&(Integer.is_odd(&1)))	
		|>	Enum.sum
require	Integer	
1..100_000	
		|>	Stream.map(&(&1	*	3))	
		|>	Stream.filter(&(Integer.is_odd(&1)))	
		|>	Enum.sum
Enum.sum(Enum.filter(Enum.map(1..100_000,	&(&1	*	3)),	&(Integer.is_odd(&1))))
[1..10000]	
		|>	List.map	(fun	x	->	x	*	3)	
		|>	List.filter	(fun	x	->	x	%	2	=	0)	
		|>	List.reduce	(fun	x	y	->	x	+	y)
List.reduce	(fun	x	y	->	x	+	y)	(List.filter	(fun	x	->	x	%	2	=	0)	(List.map	(fun	x	->	x	*	3)	[1..10000]))
Feature
Envy
(1..100_000)	
		.map	{	|x|	x	*	3	}	
		.select(&:odd?)	
		.reduce(&:+)
Linux Piping and
Redirection
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
netstat	-rn		
		|	awk	'/default/	{	print	$NF	}'		
		|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
|	head	-1	|	xargs	-I	{}		ifconfig	{}		
		|	awk	'/ether/	{print	$2}'
Foo.run_cmd("-rn",	"netstat")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/default/)))	
		|>	Enum.map(&(String.split(&1)))	
		|>	Enum.map(&(List.last(&1)))
|	awk	'/ether/	{print	$2}'
Foo.run_cmd("-rn",	"netstat")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/default/)))	
		|>	Enum.map(&(String.split(&1)))	
		|>	Enum.map(&(List.last(&1)))	
		|>	hd	|>	Foo.run_cmd("ifconfig")
Foo.run_cmd("-rn",	"netstat")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/default/)))	
		|>	Enum.map(&(String.split(&1)))	
		|>	Enum.map(&(List.last(&1)))	
		|>	hd	|>	Foo.run_cmd("ifconfig")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/ether/)))	
		|>	List.first	|>	String.split	|>	List.last
Quick
Prototyping
Foo.run_cmd("-rn",	"netstat")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/default/)))	
		|>	Enum.map(&(String.split(&1)))	
		|>	Enum.map(&(List.last(&1)))	
		|>	hd	|>	Foo.run_cmd("ifconfig")	
		|>	String.split("n")	
		|>	Enum.filter(&(String.match?(&1,	~r/ether/)))	
		|>	List.first	|>	String.split	|>	List.last
`netstat	-rn`	
		.split("n")	
		.select	{	|x|	x	=~	/default/	}	
		.map	{	|x|	x.split("	")	}	
		.map	{	|x|	x.last	}	
		.first	|>	{	|card|	`ifconfig	#{card}`	}	
		.split("n")	
		.select	{	|x|	x	=~	/ether/	}	
		.first.split("	").last
`netstat	-rn`	
		.split("n")	
		.select	{	|x|	x	=~	/default/	}	
		.map	{	|x|	x.split("	")	}	
		.map	{	|x|	x.last	}	
		.first	|>	{	|card|	`ifconfig	#{card}`	}	
		.split("n")	
		.select	{	|x|	x	=~	/ether/	}	
		.first.split("	").last
x	=	`netstat	-rn`	
		.split("n")	
		.select	{	|x|	x	=~	/default/	}	
		.map	{	|x|	x.split("	")	}	
		.map	{	|x|	x.last	}	
		.first	
`ifconfig	#{x}`	
		.split("n")	
		.select	{	|x|	x	=~	/ether/	}	
		.first.split("	").last
CM(`netstat	-rn`)	
		.split("n")	
		.select	{	|x|	x	=~	/default/	}	
		.map	{	|x|	x.split("	")	}	
		.map	{	|x|	x.last	}	
		.first.chain	{	|card|	`ifconfig	#{card}`	}	
		.split("n")	
		.select	{	|x|	x	=~	/ether/	}	
		.first.split("	").last	
		.unwrap
CM(`netstat	-rn`)	
		.split("n")	
		.select	{	|x|	x	=~	/default/	}	
		.map	{	|x|	x.split("	")	}	
		.map	{	|x|	x.last	}	
		.first.chain	{	|card|	`ifconfig	#{card}`	}	
		.split("n")	
		.select	{	|x|	x	=~	/ether/	}	
		.first.split("	").last	
		.unwrap
#	Gemfile	
gem	"chainable_methods",	"~>	0.2.1"
DATA
TRANSFORMATION
WORKFLOWS
Avoid
Temporary
Variables
text		=	"hello	http:///www.goruco.com	world"	
url			=	URI.extract(text).first	
uri			=	URI.parse(url)	
body		=	open(uri).read	
title	=	Nokogiri::HTML(body).css(“h1")	
							.first.text.strip
CM("hello	http:///www.goruco.com	world")	
		.chain	{	|text|	URI.extract(text).first	}	
		.chain	{	|url|		URI.parse(url)	}	
		.chain	{	|uri|		open(uri).read	}	
		.chain	{	|body|	Nokogiri::HTML(body).css("h1")	}	
		.first.text.strip	
		.unwrap
CM("hello	http:///www.goruco.com	world")	
		.URI.extract.first	
		.URI.parse	
		.chain	{	|uri|	open(uri).read	}	
		.HTML.parse	
		.css("h1").first.text.strip	
		.unwrap
include	Nokogiri
THANKS!
www.codeminer42.com
@akitaonrails

More Related Content

More from Fabio Akita

Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Fabio Akita
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to RubyFabio Akita
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIFabio Akita
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening KeynoteFabio Akita
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017Fabio Akita
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APFabio Akita
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017Fabio Akita
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017Fabio Akita
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016Fabio Akita
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Fabio Akita
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraFabio Akita
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilFabio Akita
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilFabio Akita
 
Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaElixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaFabio Akita
 
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada Santista
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada SantistaElixir: Tolerância a Falhas para Adultos - OneDay Baixada Santista
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada SantistaFabio Akita
 
Evento Codeminer UFRN 2016
Evento Codeminer UFRN 2016Evento Codeminer UFRN 2016
Evento Codeminer UFRN 2016Fabio Akita
 
QCON SP 2016 - Elixir: Tolerância a Falhas para Adultos
QCON SP 2016 - Elixir: Tolerância a Falhas para AdultosQCON SP 2016 - Elixir: Tolerância a Falhas para Adultos
QCON SP 2016 - Elixir: Tolerância a Falhas para AdultosFabio Akita
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In SantosFabio Akita
 
Restrição == inovação - 17o Encontro Locaweb SP
Restrição == inovação  - 17o Encontro Locaweb SPRestrição == inovação  - 17o Encontro Locaweb SP
Restrição == inovação - 17o Encontro Locaweb SPFabio Akita
 
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015Fabio Akita
 

More from Fabio Akita (20)

Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TI
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening Keynote
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - AP
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All Evil
 
Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaElixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
 
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada Santista
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada SantistaElixir: Tolerância a Falhas para Adultos - OneDay Baixada Santista
Elixir: Tolerância a Falhas para Adultos - OneDay Baixada Santista
 
Evento Codeminer UFRN 2016
Evento Codeminer UFRN 2016Evento Codeminer UFRN 2016
Evento Codeminer UFRN 2016
 
QCON SP 2016 - Elixir: Tolerância a Falhas para Adultos
QCON SP 2016 - Elixir: Tolerância a Falhas para AdultosQCON SP 2016 - Elixir: Tolerância a Falhas para Adultos
QCON SP 2016 - Elixir: Tolerância a Falhas para Adultos
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos
 
Restrição == inovação - 17o Encontro Locaweb SP
Restrição == inovação  - 17o Encontro Locaweb SPRestrição == inovação  - 17o Encontro Locaweb SP
Restrição == inovação - 17o Encontro Locaweb SP
 
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015
languages.map(&:latest).reduce(&:future).sort.first - Rupy Campinas 2015
 

Goruco 2016 - Pipe Operator for Ruby