Developing Your Own Flux Packages (InfluxDays L...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Developing Your Own Flux Packages (InfluxDays London 2019)

Flux is easy to contribute to, and it is easy to share functions and libraries of Flux code with other developers. Although there are many functions in the language, the true power of Flux is its ability to be extended with custom functions. In this session, David will show you how to write your own custom function to perform some new analytics.

David McKay

June 14, 2019

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

65 slides
  1. > ʭ = () => "I don't know what this

    symbol is called" > ʭ () -> string > ʭ() I don't know what this symbol is called
  2. > hotdog = () => “Armour !” > hotdog() >

    Armour ! > = () => “Armour Hotdog!” Error: invalid statement @1:1-1:5:
  3. package rawkode gitHubHandle = “rawkode” hello = () => "Hello"

    awesomeThings = ["BBQ", "Hot Sauce", “”]
  4. // rand with 1 param: max semantic.NewFunctionPolyType(semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{ "max":

    semantic.UInt }, Required: semantic.LabelSet{"max"}, Return: semantic.UInt, }), // in Go: func rand(max uint) uint
  5. // rand with 2 param: min, max semantic.NewFunctionPolyType(semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{

    "min": semantic.UInt, "max": semantic.UInt }, Required: semantic.LabelSet{"min", "max"}, Return: semantic.UInt, }), // in Go: func rand(min uint, max uint) uint
  6. // No Error Checking func() (values.Value, error) { goRand :=

    rand.New(rand.NewSource(...)) return values.NewFloat(goRand.Intn(100)), nil }
  7. func(args values.Object) (values.Value, error) { max, ok := args.Get("max") if

    !ok { return nil, errors.New("missing argument max") } if max.Type().Nature() == semantic.UInt { goRand := rand.New(rand.NewSource(time.Now().UnixNano())) return values.NewFloat(goRand.Intn(max.UInt())), nil } return nil, fmt.Errorf( "cannot convert argument of type %v to uint", v.Type().Nature() ) }

More Decks by David McKay

Other Decks in Technology