compile `if` into ternary, smarter .apply