#(int|string|decimal)[] mapped to a record

1 messages · Page 1 of 1 (latest)

fleet ermine
crude quail
#

Can you share an example for what kind of record/conversion you want to do?

To convert to a string array you can use a query expression or the array:map function

function toString((int|string|decimal)[] values) returns string[] => 
    from var value in values select value.toString();
function toString((int|string|decimal)[] values) returns string[] => 
    values.'map(value => value.toString());
fleet ermine
#

Just to convert into a record containing string types

public type Items record {|
    string name;
    string email;
    string password;
|};

Converting the string array[] to a array of Items

Items[] 

Anyways, what you provided would be ideal and for the above conversion I would just have to point to that element and store it in the appropriate variable within record.

#

Thanks alot @crude quail

crude quail
#

You'd still need to explicitly specify the fields in a mapping constructor, right? I would skip the conversion to a string array if so and do something like

public type Item record {|
    string name;
    string email;
    string password;
|};

function toString((int|string|decimal)[] values) returns Item => {
    name: values[0].toString(), // or string `${values[0]}`
    email:  values[1].toString(),
    password: values[2].toString()
};