This file contains functions that has to deal with functions
🤣
- compute - Compute a result using a value and a function
- call - A neater way to call an inline function
Compute a result using a value and a function
import {compute} from "js-genie/utils/functions";
compute(2, (value) => value * 2) // 4
// a little bit more complex
compute(2, (value) => {
const result = value * 2;
return result + 1;
}) // 5
A neater way to call an inline function
import {call} from "js-genie/utils/functions";
const formattedDate = call(() => {
const date = new Date();
return date.toLocaleDateString();
});
// is the same as
const formattedDate = (() => {
const date = new Date();
return date.toLocaleDateString();
})();