Skip to content

Instantly share code, notes, and snippets.

@Maxim-Filimonov
Last active August 29, 2015 14:27
Show Gist options
  • Save Maxim-Filimonov/1fa3e78f0172dbe7fc6f to your computer and use it in GitHub Desktop.
Save Maxim-Filimonov/1fa3e78f0172dbe7fc6f to your computer and use it in GitHub Desktop.
Magic of Ramda maybes
createLogo() {
R.compose(R.map(function (v) {
return <img src={v}/>
}), R.pluck('logo'), RF.Maybe);
},
defaultLogo() {
return undefined;
},
render() {
if (!this.data.loading) {
return (
<div className="ui container">
<header style={this.style.header} className="ui centered grid">
{this.createLogo(this.data.event).getOrElse(this.defaultLogo())}
</header>
{this.renderContent()}
</div>
)
@Svetixbot
Copy link

It looks like getOrElse is in the wrong place: transformation to dom happens only if you have value out of the this.data.event

@Svetixbot
Copy link

And holyshit:
what is wrong with syntax.. all you need is:

Maybe.from(this.data.which.can.return.nil).getOrElse(this.default).andThen(transformToDom)

@Svetixbot
Copy link

Anyway, you need:
Compose(createDomForImg, Maybe(this.data.event).getOrElse(this.default))

@Maxim-Filimonov
Copy link
Author

That is called point free programMing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment