Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active December 5, 2017 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/1763ce04f554702af57996253d75aa73 to your computer and use it in GitHub Desktop.
Save barneycarroll/1763ce04f554702af57996253d75aa73 to your computer and use it in GitHub Desktop.
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
)
@JAForbes
Copy link

JAForbes commented Dec 4, 2017

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!

@barneycarroll
Copy link
Author

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