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
  • Seq module functions
  • map
  • collect
  • choose
  • filter
  • groupBy
  • forAll
  • exists
  • takeWhile
  • skipWhile
  • indexed
  • toLookup
  • fold
  • scan
  • zip
  • reverse
  • updateAt

Was this helpful?

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

Seq module

The Seq (short for "sequence") module contains functions for working with sequences of data.

Seq module functions

map

Signature: (self sequence: T*, mapper: T -> U) -> U*

Calls the mapper function on each element of the original sequence, returning a new lazy sequence with the results.

open Seq;

let languages = [
     { name: "Swedish", code: "sv" },
     { name: "Tamil", code: "ta" },
     { name: "Dutch", code: "nl" },
]

return languages.map(l => l.name); // returns ["Swedish", "Tamil", "Dutch"]

collect

Signature: (self sequence: T*, collector: T -> U*) -> U*

Calls a collector function on each element of the original sequence, expecting some sequence as a result. The resulting sequences for each element are flattened into one single sequence.

open Seq

let users = [
     { name: "Frida", groupIds: [12, 144] },
     { name: "Hassan", groupIds: [30, 1] }
];

return users.collect(u => u.groupIds); // returns [12, 144, 30, 1]

If you are familiar with other programming languages, you may recognize this as the "flatMap" or "SelectMany" function.

choose

Signature: (self sequence: T*, choose: T -> U?) -> U*

Calls the chooser function on each element of the original sequence, returning a new sequence containing all the results that are not null.

open Seq;

let employees = [
    { name: "Birgitta", location: null },
    { name: "Comanche", location: "USA" },
    { name: "Theodor", location: "Germany" }
];

return employees.choose(e => e.location); // returns ["USA", "Germany"]

The choose function also is useful for simply filtering out the null values from a sequence of nullable values:

open Seq;

let xs = [1, 2, null, 3];
return xs.choose(x => x);

filter

Signature: (self sequence: T*, predicate: T -> boolean) -> T*

Calls the predicate on each element of the original sequence, returning a new lazy sequence containing the elements for which the predicate return true.

open Seq;

let boxes = [
    { id: 1, weight: 100 },
    { id: 2, weight: 25 },
    { id: 3, weight: 300 }
]

return boxes.filter(b => b.weight > 50);

groupBy

Signature: (self sequence: T*, keySelecor: T -> U) -> { key: U, values: T* }*

Groups the elements in the sequence by the key returned by the keySelector function, returning a new sequence where each group is a record containing the group key and the sequence of elements with that group key.

open Seq;

let users = [
    { id: 0, department: 'IT' },
    { id: 1, department: 'Manufacturing' },
    { id: 2, department: 'IT' }
];

// Group the users by department
return users.groupBy(u => u.department);

forAll

Signature: (self sequence: T*, predicate: (T -> boolean)) -> boolean

Returns a value indicating whether all elements in the sequence satisfy the predicate. If the sequence is empty, the function returns true.

open Seq;

let xs = [1, 2, 4];

function isEven(n: number) => n mod 2 == 0;

// Return a value indicating whether all the numbers in "xs" are even.
return xs.forAll(x => isEven(x));

exists

Signature: (self sequence: T*, predicate: (T -> boolean)) -> boolean

Returns a value indicating whether at least one element in the sequence satisfies the predicate. If the sequence is empty, the function returns false.

open Seq;

let xs = [1, 2, 4];

function isEven(n: number) => n mod 2 == 0;

// Return a value indicating whether any numbers in "xs" is even.
return xs.exists(x => isEven(x));

takeWhile

Signature: (self sequence: T*, predicate: T -> boolean) -> T*

Returns all elements from the beginning of the sequence for which the predicate returns true.

open Seq;

let numbers = range(1, 1000);

return numbers.takeWhile(n => n < 10);

skipWhile

Signature: (self sequence: T*, predicate: T -> boolean) -> T*

Discards the elements at the beginning of the sequence for the predicate returns true, returning all remaining elements.

open Seq;

let numbers = range(1, 10);

return numbers.skipWhile(n => n < 5);

indexed

Signature: (self sequence: T*) -> { index: number, value: T }*

Wraps each element in a record containing a (0-based) element number and the original element.

open Seq;

let orders = [
    { orderNo: 'B23455', customerId: 1120 },
    { orderNo: 'B23456', customerId: 3450 }
];

// Add a number to each order
return orders.indexed();

toLookup

Signature: (self sequence: T*, keySelector: T -> U) -> (U -> T*)

Creates a lookup function which allows fast access to subsets of a sequence by some key. Conceptually similar to grouping, the toLookup function is a good optimization tool if the same sequence is accessed by some key often (in a loop, for example),.

open Seq;

let posts = [
    { userId: 1, title: "Lorem ipsum" },
    { userId: 1, title: "Dolor sit amet" },
    { userId: 2, title: "Consectetur adipiscing elit" }
]

// Create a lookup from user ID to posts by that user
let lookup = posts.toLookup(p => p.userId);

// Return all posts created by used ID 1
return lookup(1);

fold

Signature: (self sequence: T*, seed: U, folder: (U, T) -> U) -> U

Calls the folder function on each successive element of the sequence, threading the result of the previous element into the next and using the seed value for the first item.

The fold function is famously expressive and can be used to implement many other functions.

// Use fold to implement a function returning the maximum
// of a sequence of nonnegative numbers:

open Seq;

function maximum(self xs: number*) => xs.fold(0, max);

return [1, 5, 2].maximum();

scan

Signature: (self sequence: T*, seed: U, folder: (U, T) -> U) -> U*

Similar to fold but returns a sequence of each intermediate state created during the folding process.


open Seq;

// Calculate a cumulative sum using the Scan function

let numbers = [1, 2, 3];

// For each number in the sequence, add it to the sum of the previous numbers.
return numbers.scan(0, (acc, next) => acc + next); // result will be [0, 1, 3, 6]

zip

Signature: (self sequence: T*, other: U*, combiner: (T, U) -> V): V*

Places two sequences side-by-side and uses the combiner function on each successive pair of elements to create some resulting value.

open Seq;

// Create the score card for players 1 and 2.
let player1Score = [1, 0, 0, 3];
let player2Score = [6, 2, 0, 0];

// Calculate the maximum score for each round
let maxScorePerRound = player1Score.zip(player2Score, max);

// Calculate the total score for each round
let totalScorePerRound = player1Score.zip(player2Score, (a, b) => a + b);

return { maxScorePerRound, totalScorePerRound };

reverse

Signature: (self sequence: T*) -> T*

Returns a cope of the sequence with elements in reverse order.

open Seq;

return ["A", "B", "C"].reverse() // returns ["C", "B", "A"]

updateAt

Signature: (self sequence: T*, index: number, replacement: T) -> T*

Returns a copy of the sequence with the element at the position indicated by the zero-based index parameter replaced by the replacement value.

open Seq;

// Replace the element at index 1 with "_"
return ["A", "B", "C"].updateAt(1, "_"); // returns ["A", "_", "C"]
PreviousDateTime moduleNextHTTP module

Last updated 4 months ago

Was this helpful?

⏸️