Sagar Suri
01/18/2020, 2:23 AMboolean
. Should I wrap the return type with Either
or what will be a better return type?Michael Marth
01/18/2020, 8:56 AMboolean
. Just leave it as it is.Sagar Suri
01/18/2020, 9:52 AMMichael Marth
01/18/2020, 9:55 AMraulraja
01/18/2020, 9:51 PMraulraja
01/18/2020, 9:52 PMSagar Suri
01/19/2020, 6:12 AMfun isSpoofingEnabled(): Boolean {
return featureToggle.isEnabled(FEATURE_SPOOFING)
}
fun getModel(): Single<LocationModel> {
return if(isSpoofingEnabled()){
Single.just(SpoofedModel())
} else {
Single.just(OriginalModel())
}
}
Correct me if I am wrong here, what I have understood so far about FP is a pure function should not have conditional statements. So I was looking for a wrapper which could provide me something like map
or flatmap
to return a different type based on the boolean value.kyleg
01/19/2020, 6:35 AMfun squareRoot(x: Int): Option<Int> {
if(x>=0) return Some(Math.sqrt(x))
else return None
}
is a perfectly pure function.kyleg
01/19/2020, 6:36 AMisSpoofingEnabled
, is not pure. This is because it appears to be accessing a non-local variable, featureToggle
kyleg
01/19/2020, 6:40 AMfeatureToggle.isEnabled = { true }
isSpoofingEnabled() // returns true
featureToggle.isEnabled = { false }
isSpoofingEnabled() // returns false
Same isSpoofingEnabled
called with same (non-existent) parameters, but different result. This means it’s not pure.
Any function with no parameters passed in, or that returns Unit, is most likely going to be non-pure, because if it were pure, it couldn’t do anything.raulraja
01/19/2020, 10:43 AMkyleg
01/19/2020, 10:30 PMfeatureToggle
I assumed isEnabled
is a mutable boolean, but I guess it could be immutable and I was just assuming.raulraja
01/19/2020, 10:43 PMSagar Suri
01/20/2020, 3:20 AMfeatureToggle
basically will check if Firebase remote config is enabled, then it will feature value from there or it will get value from local store.raulraja
01/20/2020, 7:20 AMSagar Suri
01/20/2020, 7:28 AM