underscore.lifted
v1.1.1
Published
Common elements
Downloads
3
Readme
underscore.lifted
Some simple functional helpers for underscore.
Example Usage
Simple if/else logic can be replaced with expressions:
Before:
a = f();
let res;
if (a > 100) {
res = 'big number';
} else {
res = 'small number';
}
After:
a = f();
const res = (
_.lift(a > 100)
.map(() => 'big number')
.orElse(() => 'small number')
.unlift()
);
Sure, you can use ternary operators for this. But with large expressions this can be harder to read. For example with react:
render() {
return (
_.lift(this.props.property)
.map((property) =>
<div>
<p>There's complicated information in here:</p>
{property}
</div>
)
.orElse(() =>
<div />
)
.unlift()
);
}