Flow Connect Help
Roadmap
  • â„šī¸This is Flow Connect
    • Overview
    • Technical overview
      • System requirements
    • What's new?
      • Change log
  • â–ļī¸quick start
    • Create an application
    • Create an admin access group
  • 🔁working with Connect
    • Connect to systems
      • Connector agents
        • Add agent group
        • Install agent manager
        • Add agent
        • Manage agent
      • Connectors
        • IFS Applications 10
        • Oracle
        • Microsoft SQL Server
        • Send Email
        • REST
          • Microsoft Graph API
          • Infor M3 REST
            • Obtaining Infor ION API file
            • Configure REST Connector with ION API file
          • IFS Cloud
            • IAM Client Registration
            • Obtaining end-point info from IFS Cloud
            • Configure REST Connector for IFS Cloud
      • Redirect URIs
    • Create and design
      • Application packages
      • Applications
        • Create
        • Design
        • Test
        • Commit
      • Portal Pages
        • Create Portal Page
        • Design Portal Page
        • Commit Portal Page
      • Components
        • Create component
        • Manage component
      • Modules
        • Create module
        • Manage module
      • Automations
        • Functionality
        • Create Automation
        • Manage Automation
        • Creating Access Key
        • Executing Automations Externally
          • IFS Cloud
          • Salesforce Apex Trigger Example
    • Deploy
      • Environments
      • Deploy
    • Use
      • On mobile devices
      • In web browser - Web client
      • In web browser - Portal
    • Share
      • Share Applications
    • User administration
      • Users
        • Invite a new user
        • Manage users
      • User groups
        • Create user groups
        • Manage user groups
      • Access
        • Manage access
  • â¸ī¸Reference
    • How-to guides
      • Create User Step controls
        • Header
        • Static text
        • Labelled static text
        • Link
        • Image viewer
        • Text input
        • Numeric input
        • Date input
        • Time input
        • Check box input
        • Binary option input
        • List selection input
        • List multi-selection input
        • Menu selection input
        • Data grid
        • Calendar control
        • Image selection input
        • List presentation
        • Camera Input
      • Dependent controls in User step
        • Variable source
        • Expression source
        • Control visibility (condition to hide)
      • Configure SSO for Microsoft Entra
    • Reference
      • Clients
        • Settings
        • My data
      • Designer
        • Controls
          • Header
          • Static text
          • Labeled static text
          • Link
          • External app launcher
          • Image viewer
          • Text input
          • Numeric input
          • Date input
          • Time input
          • Check box input
          • Binary option input
          • List selection input
          • List multi-selection input
          • Menu selection input
          • Data grid
          • Calendar
          • Image selection input
          • List presentation
          • Camera input
          • File gallery
          • GPS location input
          • Signature capture input
          • Item creation sub task
          • Check list sub task
          • Verb sub task
        • Steps
          • Start
          • User interaction
          • External system
          • Decision
          • Assertion
          • HTTP requests
          • Assignment
          • Table
          • Event listener
          • Checkpoint
          • Script
          • Annotation
          • End
          • Local data resource
      • Portal
        • Design items
          • Portlets
            • Accumulation chart
            • Base chart
            • Circular gauge
            • Custom content
            • Data tree
            • Document viewer
            • Filter
            • Kanban
            • KPI card
            • Link
            • My apps
            • Record
            • Rich text
            • Table
          • Container
          • Common portlet configuration
            • General
            • Events
            • Data
            • Custom buttons
            • Style
        • Portal settings
          • Branding
          • Page
          • Navigation
        • Profile
        • Portlet actions
        • Cache
        • Input to Start Step
      • Diagnostic mode
      • FlowScript
        • Walkthrough
          • Introduction
          • Expressions and programs
          • Anatomy of a program
          • Variables
          • Simple types
          • Nullable types
          • Records
          • Sequences
          • Other types
          • Arithmetic
          • Other expressions
          • Queries
          • Conditionals and loops
          • Function definitions
          • Built-in functions
          • DateTime module
          • Seq module
          • HTTP module
          • CSV module
          • JSON module
          • Trace module
          • Record module
          • XML Module
          • Custom modules
          • Custom Types
          • Appendix: Subtyping rules
          • Appendix: Escape sequences
          • Appendix: Type checking errors
      • Flowscript Copilot
      • Glossary
    • Flow Connect Downloads
      • Install Flow Connect Designer
    • Migrate from Flow Classic
      • Portal - migrate from Flow Classic
      • Classic vs. Connect Comparison Guide
Powered by GitBook
On this page
  • Functions
  • Self functions
  • Lambda expressions
  • Advanced: Variadic functions
  • Advanced: Generic functions

Was this helpful?

  1. Reference
  2. Reference
  3. FlowScript
  4. Walkthrough

Function definitions

Functions

You can declare a new function using a function statement.

// Example: create a function which takes a number 'n' as argument
// and returns n squared.

function square(n: number) {
    return n * n;
}

return square(4);

If you omit the argument type for a function, it is assigned the type primitive.

The return type of a function is inferred from its body. It is also possible to specify it explicitly:

// Example: a function with an explicit return type.
function square(n: number) : number {
    return n * n;
}

return square(3);

All functions must return some value. Functions with explicitly declared return types can call themselves recursively.

For short function that immediately return a value, you can omit the curly braces and the return keyword and instead use the lambda arrow syntax:

// Example: a couple of functions declared using the lambda arrow syntax

function square(n: number) => n * n;

function abs(n: number) =>
    case when n < 0 then n * -1
         else n
         end;

Self functions

The first argument of a function may be decorated with the self keyword, turning the function into a self function. When calling a self function, the first argument may be supplied using dot notation:

function multiply(self n: number, m: number) : number {
    return n * m;
}

return 3.multiply(2); // the first argument is supplied by the left side of the dot.

Lambda expressions

A lambda expression is a terse syntax for creating anonymous function values. A lambda expression is written using an argument list followed by a lambda arrow and a single return expression.

// Example: declare a function using a lambda expression.
let add = (x, y) => x + y;
return add(2, 3);

For single-argument lambda expressions, the parantheses around the argument list may be omitted:

// Example: a single-argument lambda expression.
let square = x => x * 2;
return square(3);
// Example: get a list of user names using the Seq.map function
// together with a lambda expression

open Seq;

let users = [
    {id: 0, name: "Gustava"},
    {id: 1, name: "Farid"}
];

return users.map(u => u.name); // here, 'u' gets its type from its surroundings.

Advanced: Variadic functions

A variadic function is a convenience allowing you to pass a sequence argument as individual arguments. A variadic argument is marked by three periods (...) before the argument name.

// Define a "maximum" function which takes any number of arguments.
function maximum(...xs: number*) {
    let started = false;
    let result = 0;
    for x in xs {
        if not started or x > result {
            set result = x;
            set started = true;
        }
    }
    return isNull(result, 0);
}

return maximum(10, 3, 5, 11)

Advanced: Generic functions

A generic function leaves some of its constituent types – argument types or return type – purposely undefined, replacing them with type variables. This allows the function to operate on different kinds of values while retaining type safety.

In the following example, the function second is defined with one type variable called T, declared in the angle brackets after the function name. This makes the function return number? when called on a list of numbers, text? when called on a list of texts, etc.

// Example: create a generic function which returns the second element
// of a sequence (or null if there are less than two elements).

function second<T>(self xs: T*): T? {
    return xs.skip(1).firstOrNull();
}

let secondNumber = [1, 2, 3].second(); // has type 'number?'
let secondText = ["hello", "world"].second(); // has type 'text?'
PreviousConditionals and loopsNextBuilt-in functions

Last updated 3 months ago

Was this helpful?

Typically used in conjunction with the module, lambda expressions provide the benefit of inferring their argument types from the context:

â¸ī¸
Seq