Hi, what would be the alternative for `option.fx {...
# arrow
c
Hi, what would be the alternative for
option.fx {}
? this cannot be achieved with nullable, right? should I replace it with
either.fx { }
?
Copy code
class DebitCardNumber private constructor(
    val number: String
) {
    companion object {
        private const val Mastercard = "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}\$"

        suspend operator fun invoke(number: String): Either<Unit, DebitCardNumber> =
            if (number.matches(Mastercard.toRegex())) DebitCardNumber(number).right() else Unit.left()
    }
}
Copy code
IO.fx {
            val validCardNumber = !effect { DebitCardNumber(cardNumber) }
            Either.fx<Unit, DebitCard> {
                VirtualDebitCard(
                    cardNumber = !validCardNumber,
                    accountNumber = accountNumber ?: "",
                    contractNumber = contractNumber ?: "",
                    cardStatus = cardStatus ?: "",
                    cancelIndicator = cancelReason ?: "",
                    cancelReason = cancelIndicator ?: "",
                    cardAlias = cardAlias ?: ""
                )
            }

        }.suspended()
s
It can be achieved for
nullable
, and someone is contributing it 🙂 https://github.com/arrow-kt/arrow-core/pull/251
c
Copy code
sealed class Shift<out T>
object Empty : Shift<Nothing>()
data class Result<T>(val result: T) : Shift<T>()
is this wrap needed?
k
No, that wrap will be eliminated in the next commit, the guys helped me how to avoid this scenario, which means no wrapping performance penalty for continuation.
c
👍