A
arktype•5d ago
JesusTheHun

`narrow` vs `satisfying`

I've ran across both functions, I can see the signatures are the same, but the type are not. I was wondering what the different is, between the two ?
7 Replies
Dimava
Dimava•5d ago
One is for input another is for output Or something So it's different for morphs only
JesusTheHun
JesusTheHunOP•5d ago
Or something
?? 😂
Dimava
Dimava•5d ago
Well I didn't use it myself so can't say for sure
JesusTheHun
JesusTheHunOP•5d ago
kk, I'll try to compare the two with in/out
TizzySaurus
TizzySaurus•5d ago
narrow(predicate: Predicate): BaseRoot {
return this.constrainOut("predicate", predicate)
}

satisfying(predicate: Predicate): BaseRoot {
return this.constrain("predicate", predicate)
}
narrow(predicate: Predicate): BaseRoot {
return this.constrainOut("predicate", predicate)
}

satisfying(predicate: Predicate): BaseRoot {
return this.constrain("predicate", predicate)
}
this is the difference in the source code narrow applies the constraint to the output, whereas satisfying applies the constraint to the input
JesusTheHun
JesusTheHunOP•5d ago
so to see an actual difference, I would need to pipe the type in order to alter its input, correct ?
TizzySaurus
TizzySaurus•5d ago
There'd need to be some form of transform, yes. Not necessarily a .pipe() explicitly though. E.g.:
type("string.numeric.parse").narrow(x => {...}) // `x` is a number
type("string.numeric.parse").satisfying(x => {...}) // `x` is a string
type("string.numeric.parse").narrow(x => {...}) // `x` is a number
type("string.numeric.parse").satisfying(x => {...}) // `x` is a string
Want results from more Discord servers?
Add your server