Giter VIP home page Giter VIP logo

railway's Introduction

Railway

Build Status

This library is based on a post from (Scott Wlaschin)[https://fsharpforfunandprofit.com/posts/recipe-part2/] in order to bring Railway Oriented Programming to PHP.

Installation

Install it using Composer

composer require martinezdelariva/railway 

Motivation

Typically every use case receives a request and produces a response. The use case passes for several steps until gets the final response to be returned. Handle every error scenario could be tedious and difficult to read.

Either

In order to have a type that works with any workflow, we borrow the type Either from functional programming:

Either

This object acts as a switch, where left means failure and the right means success.

Railway Naming Convention

Railways have switches ("points" in the UK) for directing trains onto a different track. We can think of these “Success/Failure” functions as railway switches.

  • One track function: it has 1 input and 1 output.

One track

  • Two track function: it has 2 input (Either) and 2 output (Either).

Two track

  • Switch: it has 1 input and 2 output (Either).

Switch

Functions

Please find below the list of functions which connects switch together:

Map

1-1 : 2-2

Converts one track function into two track function.

Map

Lift

Converts one track function into switch.

1-1 : 1-2

Lift

Bind

Converts switch into two track function.

1-2 : 2-2

Bind

Unite

Join two switches into another switch.

1-2 and 1-2 : 1-2

Unite

Tee

Dead-function to one track function.

Tee

TryCatch

Handling exceptions. Convert one track function into switch.

1-1 : 1-2

Try Catch

Plus

Combines switch functions in parallel.

1-2 + 1-2 : 1-2

Plus

DoubleMap

Handles both tracks, converting one track into two track function.

1-1 : 2-2

Double Map

railway's People

Contributors

martinezdelariva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hothat skie simpod

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.