Change `if` behavior
lightness opened this issue · 3 comments
lightness commented
lightness commented
Proposed example:
// Example 1
cmp()
.if(condition).then(CmpA)
.else(CmpB);
// Example 2
// Suppose comparator called with (a,b)
// If condition1(a) && condition1(b) => return CmpA(a,b).
// If condition1(a) && !condition1(b) => return () => 1
// If !condition1(a) && condition1(b) => return () => -1
// If !condition1(a) && !condition1(b) =>
// If condition2(a) && condition2(b) => return CmpB(a,b).
// If condition2(a) && !condition2(b) => return () => 1
// If !condition2(a) && condition2(b) => return () => -1
// If !condition2(a) && !condition2(b) =>
// => CmpC(a,b)
cmp()
.if(condition1).then(CmpA)
.elif(condition2).then(CmpB)
.else(CmpC);
// Example 3
cmp()
.if(conditon).then(
cmp().map(mapper1).use(asc)
)
.else(
cmp().map(mapper2).use(desc)
)
// .asc() should be equal to .use(asc)
// .desc() should be equal to .use(desc)
tresdosdos commented
Second example looks good
lightness commented
If
behavior was changed since this commit