forked from NYHTC/fm-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListConcat.xml
97 lines (75 loc) · 2.95 KB
/
ListConcat.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<fmxmlsnippet type="FMObjectList">
<CustomFunction id="422" functionArity="3" visible="True" parameters="firstList;secondList;options" name="ListConcat">
<Calculation><![CDATA[// ListConcat ( firstList; secondList; options )
// version 1.1.2, Erik Shagdar
/*
Given 2 lists, concat their values
EXAMPLE:
Input: ListConcat ( List ( 1 ; 2 ; 3 ) ; List ( "A" ; "B" ; "C" ) ; # ( "RowSep" ; "-rowsep-" ) & # ( "colSep" ; "-colsep-" ) )
Output: 1-colsep-A-rowsep-2-colsep-B-rowsep-3-colsep-C
REQUIRES:
DictContains
DictGet
DictRemove
ValueRemoveIndex
HISTORY ( recent at top ):
1.1.2 - 2018-06-14 ( dshockley ): Clarify documentation.
1.1.1 - 2017-08-24 ( eshagdar ): Added example to documentation.
1.1 - 2017-04-17 ( eshagdar ): Use ValueRemoveIndex instead of ValueRemove since lists should be allowed to have duplicate items.
1.0 - 2016-09-19 ( eshagdar ): First created.
*/
If ( options = "help" or DictGet ( options; "help" );
List (
"This functions takes 2 RETURN-delimited lists and concatenates them. Below are optional keys that can be specified in the 'options' param:";
" rowSep - string between each row of OUTPUT";
" colSep - string between the two values of OUTPUT";
" prefix - string before each value of the first list";
" suffix - string after the second value in the second list";
" ";
" help - display this message";
" listNames - names of the keys to use for the two lists. The 2 lists should exist in the options param"
);
Let ( [
rowSep = If ( DictContains ( options; "rowSep" ); DictGet ( options; "rowSep" ); ¶ );
colSep = If ( DictContains ( options; "colSep" ); DictGet ( options; "colSep" ); " " );
prefix = If ( DictContains ( options; "prefix" ); DictGet ( options; "prefix" ); "" );
suffix = If ( DictContains ( options; "suffix" ); DictGet ( options; "suffix" ); "" );
listNames = DictGet ( options; "listNames" );
firstList =
If ( not IsEmpty ( firstList );
firstList;
DictGet ( options; GetValue ( listNames; 1 ) )
);
secondList =
If ( not IsEmpty ( secondList );
secondList;
DictGet ( options; GetValue ( listNames; 2 ) )
);
firstVal_firstList = GetValue ( firstList; 1 );
firstVal_secondList = GetValue ( secondList; 1 );
remain_firstList = ValueRemoveIndex ( firstList ; 1 );
remain_secondList = ValueRemoveIndex ( secondList ; 1 );
remain_options =
If ( IsEmpty ( listNames );
options;
DictRemove (
DictRemove (
DictRemove ( options; listNames );
GetValue ( listNames; 1 )
);
GetValue ( listNames; 2 )
)
);
firstResult = prefix & firstVal_firstList & colSep & firstVal_secondList & suffix;
remainResult =
If ( not IsEmpty ( remain_firstList ) or not IsEmpty ( remain_secondList );
rowSep & ListConcat ( remain_firstList; remain_secondList; remain_options );
""
)
];
firstResult & remainResult
)
)]]>
</Calculation>
</CustomFunction>
</fmxmlsnippet>