Skip to content
/ railway Public

Pipe result tuples {:ok, value} all the way. Noop if the first element differs from :ok

License

Notifications You must be signed in to change notification settings

sorax/railway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Railway

Pipe result tuples {:ok, value} all the way. Noop if the first element differs from :ok

Tests Code Quality Hex.pm hexdocs.pm Hex.pm Downloads License

Installation & Usage

Simply add railway to your list of dependencies in your mix.exs:

def deps do
  [
    {:railway, "~> 1.0"}
  ]
end

run mix deps.get and use Railway in your Module

defmodule MyModule do
  use Railway

  def my_func do
    "https://www.example.com/api"
    ~>> Req.get()
    ~>> Map.get(:body)
    ~>> Jason.decode()
    ~>> Map.get("results")
  end
end

How does ~>> work?

The ~>> operator introduces the value of an {:ok, value} tuple on the left-hand side as the first argument to the function call on the right-hand side.

If the tuple on the left-hand side is anything different from {:ok, value} like {:error, reason} the ~>> operator will just return the left-hand side and not execute the function call on the right.

If the expression on the left-hand side is not a tuple, the ~>> operator will behave just like |> does.

Documentation can be found at https://hexdocs.pm/railway

About

Pipe result tuples {:ok, value} all the way. Noop if the first element differs from :ok

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages