Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing Your Own Flux Packages (InfluxDays London 2019)

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
Tweet

More Decks by David McKay

Other Decks in Technology

Transcript

  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() ) }