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.

69172dc4e4cc3e4cdd234c40adf395fa?s=128

David McKay

June 14, 2019
Tweet

Transcript

  1. 1.
  2. 2.
  3. 4.
  4. 11.

    > ʭ = () => "I don't know what this

    symbol is called" > ʭ () -> string > ʭ() I don't know what this symbol is called
  5. 12.

    > hotdog = () => “Armour !” > hotdog() >

    Armour ! > = () => “Armour Hotdog!” Error: invalid statement @1:1-1:5:
  6. 13.
  7. 14.

    package rawkode gitHubHandle = “rawkode” hello = () => "Hello"

    awesomeThings = ["BBQ", "Hot Sauce", “”]
  8. 17.
  9. 18.
  10. 25.
  11. 28.
  12. 29.
  13. 32.
  14. 39.

    // 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
  15. 40.

    // 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
  16. 42.

    // No Error Checking func() (values.Value, error) { goRand :=

    rand.New(rand.NewSource(...)) return values.NewFloat(goRand.Intn(100)), nil }
  17. 43.

    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() ) }
  18. 45.
  19. 47.
  20. 51.
  21. 52.
  22. 53.
  23. 54.
  24. 55.
  25. 56.
  26. 57.
  27. 58.
  28. 59.
  29. 60.
  30. 61.
  31. 62.
  32. 63.
  33. 64.
  34. 65.