# BackPipe

A simple backwards pipe operator for Elixir via the `~>` operator. Lets you pipe the output of preceding logic into the final argument position of the next function.

### Why?

Why not!

But really, this is mostly an experiment. Elixir provides both a set of reserved operators that can be overloaded and a macro system to do so. Plus, the backwards pipe operator is not a novel concept. Some other functional languages like F#, have them. This is a study of what it could look like in Elixir.

Also, it does feel useful for the small handful of cases where the final argument in a function is often the result of a chain (i.e. pipeline) of operations, like when calling `struct/2` to dynamically generating new structs.

## Docs


## Installation

If [available in Hex](, the package can be installed
by adding `back_pipe` to your list of dependencies in `mix.exs`:

def deps do
    {:back_pipe, "~> 0.1.0"}

## Examples

# Basic usage
iex> "hello world" ~> String.split()
["hello", "world"]

# We can chain too
"hello world"
~> String.split()
~> Enum.concat(["oh"])
|> Enum.join(" ")
# "oh hello world"

# More useful: dynamically creating a struct
defmodule Traveler do
  defstruct [:id, :name, :location]

  def new(kwl) do
    |> Map.put(:location, "Unknown")
    ~> struct(__MODULE__)

iex> 1, name: "Hal")
%Traveler{id: 1, location: "Unknown", name: "Hal"}