GithubHelp home page GithubHelp logo

control's Introduction

control

Save time, write better Go.

Synopsis

Shamelessly inspired by caolan/async, control aims to make the monotony of Go less, well, monotonous. Control provides a set of functional control structures, adding brevity to common cases. Please note, control is a work in progress.

Example

Control takes the redundancy out of common coding patterns. Tired of this?

func DoThings(a Variable) (e Variable, err error) {

	var b, c, d Variable

	if b, err = DoThing(a); err != nil {
		return
	}

	if c, err = DoThing(b); err != nil {
		return
	}

	if d, err = DoThing(c); err != nil {
		return
	}

	e, err = DoThing(d)
	return // how much of your life will you waste on this pattern?

}

Represent the problem functionally, such brevity!

import "github.com/azoff/control"

func DoThings(a Variable) (Variable, error) {

	doValue := func(prev control.Any) (control.Any, error) {
		next, err := DoThing(prev.(Variable))
		return control.Any(next), err
	}

	// now you're workin!
	res, err := control.Waterfall(a, doValue, doValue, doValue, doValue)
	return res.(Variable), err

}

Installation

Same ol' standard install process

go get github.com/azoff/control

API

Here are the functions currently supported in control:

  • func Serial(...SerialFunc) error

    • call one or more functions sequentially, aborting if any one has an error
  • func Waterfall(Any, ...WaterfallFunc) (Any, error)

    • call one or more funciton sequentially, passing the result of the previous function into the next
  • func Parallel(...ParallelFunc) error

    • run several functions at the same time, aborting if any one has an error

control's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.