Last active
December 5, 2017 08:18
-
-
Save barneycarroll/1763ce04f554702af57996253d75aa73 to your computer and use it in GitHub Desktop.
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
const [not, definitively] = [Symbol(), Symbol()] | |
export default const possibly = possibility => premise => alternatively => | |
[premise, ...possibility, definitively].reduce((premise, postulate) => | |
premise === not | |
? | |
alternatively | |
: | |
postulate === definitively | |
? | |
premise | |
: | |
postulate in premise | |
? | |
premise[postulate] | |
: | |
not | |
) |
It's the Material Design Lite of code styles
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry I completely missed your actual function's functionality! 😆 It's cool. Ramda has a function like this called
pathOr
.I don't agree that legibility is affected, but I also see value in what you're doing. I think the fact that in my code bases operator first applies to everything, from dot access, ternaries, addition/concatenation, logical and/or, bit shifting whatever... there's not really as much fighting on on the ternary operand expression. But I think if I wasn't so strict here, it'd seem noisier.
I am probably struggling to read your ternaries just because my mental algorithm for reading ternaries requires matching a certain pattern and I'd just need to internalize your pattern and then it'd seem just as good. But I'm generally pretty white space dense so I'm wary, but yeah it looks neat!