Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active September 28, 2022 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taruma/60610672a9bd94724cba46f68b5614fa to your computer and use it in GitHub Desktop.
Save taruma/60610672a9bd94724cba46f68b5614fa to your computer and use it in GitHub Desktop.
feid.utils | Official Lambda (LOGIC / UTILITIES FUNCTIONS) by FIAKO Engineering.
/*
fiako.utils v0.2.0
LOGIC / UTILITIES FUNCTIONS BY FIAKO ENGINEERING
GIST LOGIC/UTILITIES (feid.utils): https://gist.github.com/taruma/60610672a9bd94724cba46f68b5614fa
REPOSITORY: https://github.com/fiakoenjiniring/feidlambda
AUTHOR: @taruma, LKO
TESTED: Microsoft 365 Business v2209 (Build 15629.20156)
*/
// INDEPENDENT FUNCTIONS
// NEW IN v0.1
REPEATCOLS = LAMBDA(
vector,
[num_repeat],
LET(
num_repeat, IF(ISOMITTED(num_repeat), 2, num_repeat),
colvector, TOCOL(vector),
repeatvector, CHOOSECOLS(colvector, SEQUENCE(num_repeat,,1,0)),
TOCOL(repeatvector,,TRUE)
)
);
SORTCOLS = LAMBDA(
table,
table_header,
LET(
header, table_header,
values, table,
ncols, COLUMNS(table),
headstack, VSTACK(header, SEQUENCE(1, ncols)),
headsorted, SORT(headstack, 1, 1, TRUE),
newindex, CHOOSEROWS(headsorted, 2),
sortedvalues, CHOOSECOLS(values, newindex),
sortedheader, CHOOSEROWS(headsorted, 1),
VSTACK(sortedheader, sortedvalues)
)
);
// NEW IN v0.2
COMPAREVECTOR = LAMBDA(
left_vector,
right_vector,
LET(
left_vector, TOCOL(left_vector),
right_vector, TOCOL(right_vector),
BYROW(
left_vector, LAMBDA(
left,
OR(BYROW(
right_vector, LAMBDA(
right,
left=right
)
))
)
)
)
);
MULTICHECK = LAMBDA(
array,
search_vector,
[check_condition],
LET(
searchvector, TOROW(search_vector),
nrows, ROWS(array),
repeatarray, CHOOSEROWS(searchvector, SEQUENCE(nrows,,1,0)),
boolarray, MAP(array, repeatarray, LAMBDA(x, y, x=y)),
checkcondition, IF(ISOMITTED(check_condition), "AND", check_condition),
SWITCH(LOWER(checkcondition),
"and", BYROW(boolarray, LAMBDA(x, AND(x))),
"or", BYROW(boolarray, LAMBDA(x, OR(x))),
"INVALID CHECK CONDITION"
)
)
);
// DEPENDENT FUNCTIONS (USING PREVIOUS FUNCTIONS)
// NEW IN v0.1
REPEATROWS = LAMBDA(
vector,
[num_repeat],
LET(
num_repeat, IF(ISOMITTED(num_repeat), 2, num_repeat),
repeatvector, REPEATCOLS(vector, num_repeat),
TOROW(repeatvector,,TRUE)
)
);
RESHAPECOLS = LAMBDA(
array,
[nsplit],
LET(
nsplit, IF(ISOMITTED(nsplit), 2, nsplit),
ncols, COLUMNS(array),
nrows, ROWS(array),
divider, CEILING.MATH(ncols/nsplit),
seqarray, CHOOSEROWS(SEQUENCE(1,divider), SEQUENCE(nsplit,,1,0)),
flatseq, TAKE(TOCOL(seqarray,,TRUE),ncols),
repseq, REPEATCOLS(flatseq, nrows),
flatarray, TOCOL(array),
sortedarray, SORTBY(flatarray,repseq),
IF(
MOD(ncols, nsplit)=0,
WRAPROWS(sortedarray, nsplit, ""),
CONCAT(
"Pick another nsplit. ",
"MOD(",ncols,",",nsplit,")",
" != 0."
)
)
)
);
FINDINDEX2D = LAMBDA(
lookup_value,
array,
LET(
nrows, ROWS(array),
ncols, COLUMNS(array),
size, nrows*ncols,
colarray, TOCOL(array),
seqrows, SORT(REPEATCOLS(SEQUENCE(nrows), ncols)),
seqcols, REPEATCOLS(SEQUENCE(ncols), nrows),
idnumber, SEQUENCE(size),
lookuptable, HSTACK(idnumber, seqrows, seqcols),
FILTER(lookuptable, colarray=lookup_value)
)
);
// NEW IN v0.2
DROPROWS = LAMBDA(
array,
index_to_drop,
LET(
nrows, ROWS(array),
indexdrop, TOCOL(index_to_drop),
indexdropclean, FILTER(indexdrop, NOT(ISBLANK(indexdrop))),
seqvector, SEQUENCE(nrows),
boolvector, NOT(COMPAREVECTOR(seqvector, indexdropclean)),
FILTER(array, boolvector)
)
);
DROPCOLS = LAMBDA(
array,
index_to_drop,
LET(
transarray, TRANSPOSE(array),
droparray, DROPROWS(transarray, index_to_drop),
TRANSPOSE(droparray)
)
);
COUNTMULTICHECK = LAMBDA(
array,
search_vector,
[check_condition],
LET(
result, MULTICHECK(array, search_vector, check_condition),
SUM(INT(result))
)
);
/*
MIT License
Copyright (c) 2022 PT. FIAKO ENJINIRING INDONESIA
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment