var safeHead = function(xs) {
return S.ifElse(() => R.isNil(xs[0]), S.Nothing, S.Just, xs[0]);
};
const streetName = S.pipe([R.prop('addresses'), safeHead, R.map(R.prop('street'))]);
streetName({
addresses: []
});
Function: a bunch of code you can call. It can take any number of parameters, and it can have a name.
Closure: The context, or variables and their values around the function when it was defined.
Generator: a special function that can yield more than one result when called in a loop. Generator functions also have closures.
So to shortly answer to your question: functions can't do anything a generator cannot do; or, generators can do more. And they all have closures.
Here's a simple example to understand closures:
This file contains hidden or 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
// Lost Grid v5.1.6 - https://github.com/corysimmons/lost | |
$gutter = 30px | |
$rtl = false | |
$flexbox = true | |
/** | |
* Sets a translucent background color to all elements it affects. Helpful while setting up, or debugging, the structure of your site to make sure all items are cleared correctly. | |
* |
This file contains hidden or 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
<snippet> | |
<content><![CDATA[ | |
<div class="codemirror-fixture" data-example="${1:name}"></div>]]></content> | |
<tabTrigger>-fx</tabTrigger> | |
<scope>text.html.markdown.multimarkdown, text.html.markdown</scope> | |
<description>data-example</description> | |
</snippet> | |
<snippet> |