Last active
March 11, 2025 23:22
-
-
Save CHatmaker/3e6cba6414fadfabfa3725255da2ba74 to your computer and use it in GitHub Desktop.
BXL 5g Functions LAMBDA Modeling Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Base Template | |
/* FUNCTION NAME: <enter name here>λ | |
DESCRIPTION:*//**<this comment displays in name manager>*/ | |
/* REVISIONS: Date Developer Description | |
<changed> <your name> <what changed> | |
*/ | |
BaseTemplateλ = LAMBDA( | |
// Parameter Declarations | |
[Argument1], // All arguments must have [ ] | |
[Argument2], // Add as many arguments as needed. | |
[Argument3], | |
// Help | |
LET(Help, TRIM(TEXTSPLIT( | |
"FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
"DESCRIPTION: →Copy description from comment block at top.¶" & | |
"WEBPAGE: →URL¶" & | |
"VERSION: →copy date from last revision in REVISIONS¶" & | |
"PARAMETERS: →¶" & | |
"Argument1 →(Required) Description of required argument1¶" & | |
"Argument2 →(Required) Description of required argument2¶" & | |
"Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
"EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
"→=ID.FunctionNameλ( 123, 456)", | |
"→", "¶" ) | |
), | |
// Check inputs - Omitted required arguments (do not include optional arguments) | |
Help?, OR( ISOMITTED( Argument1), | |
ISOMITTED( Argument2 ) | |
), | |
// Set internal named constants if needed | |
// Set defaults for optional arguments if needed | |
Argument3, IF( ISOMITTED( Argument3), 0, Argument3), | |
// Procedure starts here | |
Result, Argument1 + Argument2 - Argument3, // Last Formula line goes here | |
// Return Result | |
CHOOSE(Help? + 1, Result, Help) | |
) | |
); | |
// Stacker Template | |
/* FUNCTION NAME: <enter name here>λ | |
DESCRIPTION:*//**<this comment displays in name manager>*/ | |
/* REVISIONS: Date Developer Description | |
<changed> <your name> <what changed> | |
*/ | |
StackerTemplateλ = LAMBDA( //Change this name | |
// Parameter Declarations | |
[Argument1], // All arguments must have [ ] - For this template assume this is the opening amount | |
[Argument2], // Add as many arguments as needed. | |
[Argument3], | |
// Help | |
LET(Help, TRIM(TEXTSPLIT( | |
"FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
"DESCRIPTION: →Copy description from comment block at top.¶" & | |
"WEBPAGE: →URL¶" & | |
"VERSION: →copy date from last revision in REVISIONS¶" & | |
"PARAMETERS: →¶" & | |
"Argument1 →(Required) Description of required argument1¶" & | |
"Argument2 →(Required) Description of required argument2¶" & | |
"Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
"EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
"→=ID.FunctionNameλ( 123, 456)", | |
"→", "¶" ) | |
), | |
// Check inputs - Omitted required arguments (do not include optional arguments) | |
Help?, OR( ISOMITTED( Argument1), //In this example, Argument1 is an opening balance | |
ISOMITTED( Argument2 ) //In this example, Argument2 is an array to be processed | |
), | |
// Set internal named constants if needed | |
// Set defaults for optional arguments if needed | |
Argument3, IF( ISOMITTED( Argument3), 0, Argument3), | |
// Calculate things that only need to be calculated once here | |
// Procedure | |
Result, REDUCE( Argument1, SEQUENCE( , <number of columns goes here>) , | |
LAMBDA( Accumulator, n, | |
LET( | |
// Individual Values out of arrays | |
Opening, TAKE( Accumulator, -1, -1), | |
_Argument2, INDEX( Argument2, n), | |
// Calculations | |
Calculation, Opening * _Argument2, //Replace this | |
Closing, Opening + Calculation, //Replace this | |
// Formatting the result | |
Stack, VSTACK( | |
Opening, | |
Calculation, | |
Closing | |
), | |
// Result | |
Result, IF( n = 1, | |
Stack, | |
HSTACK( | |
Accumulator, | |
Stack) | |
), | |
Result | |
) | |
) | |
), | |
IF( Help?, Help, Result) | |
) | |
); | |
// Circularity Template | |
/* FUNCTION NAME: <enter name here>λ | |
DESCRIPTION:*//**<this comment displays in name manager>*/ | |
/* REVISIONS: Date Developer Description | |
<changed> <your name> <what changed> | |
*/ | |
AverageBalanceInterestλ = LAMBDA( //Change this name | |
// Parameter Declarations | |
[CashBeforeInt], // Add as many arguments as needed. | |
[BeginningDebt], // All arguments must have [ ] | |
[InterestRate], // Change these names to suit | |
// Help | |
LET(Help, TRIM(TEXTSPLIT( | |
"FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
"DESCRIPTION: →Copy description from comment block at top.¶" & | |
"WEBPAGE: →URL¶" & | |
"VERSION: →copy date from last revision in REVISIONS¶" & | |
"PARAMETERS: →¶" & | |
"Argument1 →(Required) Description of required argument1¶" & | |
"Argument2 →(Required) Description of required argument2¶" & | |
"Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
"EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
"→=ID.FunctionNameλ( 123, 456)", | |
"→", "¶" ) | |
), | |
// Check inputs - Omitted required arguments (do not include optional arguments) | |
Help?, OR( ISOMITTED( CashBeforeInt), //Change this to match argument 1's name | |
ISOMITTED( BeginningDebt), //Change this to match argument 2's name | |
ISOMITTED( InterestRate ) //Change this to match argument 3's name | |
), | |
// Set internal named constants if needed | |
// Set defaults for optional arguments if needed | |
// Iterative function definition (fn) - Change the parameters and LET() statement to suit | |
Iterate, LAMBDA( fn, CashBeforeInt, BeginningDebt, InterestRate, AverageDebt, | |
LET(Interest, AverageDebt * InterestRate, | |
CFADS, CashBeforeInt - Interest, | |
EndingDebt, BeginningDebt - CFADS, | |
AverageDebt, Average( BeginningDebt, EndingDebt), | |
Delta, ABS( Interest - (AverageDebt * InterestRate)), | |
Result, IF( Delta < 0.01, | |
Interest, | |
fn( fn, | |
CashBeforeInt, BeginningDebt, InterestRate, AverageDebt | |
) | |
), | |
Result | |
) | |
), | |
// Procedure - Change parameters to suit | |
Result, Iterate( Iterate, CashBeforeInt, BeginningDebt, InterestRate, 0), | |
// Return result or Help | |
CHOOSE( Help? + 1, Result, Help) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment