list
fastn
, the list
keyword can be used to create an array or list of values.
The list
keyword is followed by the data type of the values that the list
will contain.list
list
-- <data-type> list <list-name>:
-- <value>
-- <value>
-- <value>
-- ...
-- end: <list-name>
Also make sure to use the end syntax -- end: <list-name>
to mark
the end of the list during initialization.
weekdays
, you would use the
following syntax:-- string list weekdays:
-- string: Sunday
-- string: Monday
-- string: Tuesday
-- string: Wednesday
-- string: Thursday
-- string: Friday
-- string: Saturday
-- end: weekdays
This creates a new variable called weekdays
, which is a list of string
s. The
list is initialized with seven strings representing the days of the week.
fastn
are immutable, which means that their contents
cannot be changed after they are initialized. However, you can make a list
mutable by prefixing it with a $
symbol, like this:-- string list $weekdays:
-- end: $weekdays
-- record person:
caption name:
body bio:
-- person list people:
-- person: Amit Upadhyay
Amit is CEO of FifthTry.
-- person: Shobhit Sharma
Shobhit is a developer at FifthTry.
-- end: people
list
of person
objects, called it people
, and
created two person
objects and inserted them the people
list.ftd.ui
type as a listftd.ui list
type or
children
type to pass a UI component in a
list.ftd.ui list
type-- ftd.ui list uis:
-- ftd.text: Hello World!
color: $inherited.colors.text-strong
-- ftd.text: I love `fastn`.
color: $inherited.colors.text-strong
-- end: uis
children
type-- foo:
-- ftd.text: Hello World!
color: $inherited.colors.text-strong
-- ftd.text: I love `fastn`.
color: $inherited.colors.text-strong
-- end: foo
-- component foo:
children uis:
... some code here
-- end: foo
Once you have created a list, you can access its elements using indexing or looping.
Once you have created a list, you can access its items using their index. Infastn
, indexing starts at 0. Or you can useloop
fastn
, you can use
the $loop$
keyword to iterate over a list. Here's an example:-- ftd.text: $obj
$loop$: $weekdays as $obj
weekdays
list on a separate line.
Similarly, To iterate over a uis
list, you would use the following syntax:-- obj:
$loop$: $uis as $obj
fastn
.You can access an element of a list by its index. In fastn
, list indexing is
zero-based, which means the first element of a list has an index of 0, the
second element has an index of 1, and so on. You can use the .
operator to
access an element of a list by its index.
weekdays
list, you would use the
following syntax:-- ftd.text: $weekdays.0
color: $inherited.colors.text-strong
uis
list, you would use the
following syntax:-- uis.0:
$processor$
$processor$
-- string list foo:
$processor$: some-list
Here the value of the list will be provided by the some-list
processor.
$processor$
as
well:-- string list $foo:
-- end: $foo
-- $foo:
$processor$: some-list