-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Falsy truthy and fix doov function #37
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #37 +/- ##
==========================================
+ Coverage 99.84% 99.84% +<.01%
==========================================
Files 47 47
Lines 1277 1285 +8
Branches 166 166
==========================================
+ Hits 1275 1283 +8
Partials 2 2
Continue to review full report at Codecov.
|
src/doov.ts
Outdated
@@ -167,7 +167,8 @@ export function sum(...values: NumberFunction[]): NumberFunction { | |||
return new NumberFunction(new NaryMetadata(values.map(value => value.metadata), SUM), (obj, ctx) => { | |||
return values.reduce((previous, value) => { | |||
const v = value.get(obj, ctx); | |||
return v != null ? previous + v : previous; | |||
// @ts-ignore : Here we are sure that v is neither null or undefined since Boolean(v) would return false. Furthermore, previous + 0 <=> previous. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace that with not null && not undefined ? previous + v : previous
src/doov.ts
Outdated
@@ -158,7 +158,7 @@ export function count(...values: BooleanFunction[]): NumberFunction { | |||
return new NumberFunction(new NaryMetadata(values.map(value => value.metadata), COUNT), (obj, ctx) => { | |||
return values.filter(value => { | |||
const v = value.get(obj, ctx); | |||
return v != null ? v : false; | |||
return Boolean(v) || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove || false
src/doov.ts
Outdated
@@ -149,7 +149,7 @@ export function matchNone(...values: BooleanFunction[]): BooleanFunction { | |||
return new BooleanFunction(new NaryMetadata(values.map(value => value.metadata), NONE_MATCH), (obj, ctx) => { | |||
return values.every(value => { | |||
const v = value.get(obj, ctx); | |||
return v != null ? !v : false; | |||
return !v || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!Boolean(v)
src/dsl/lang/BooleanFunction.ts
Outdated
public isTruthy(): BooleanFunction { | ||
return new BooleanFunction( | ||
new UnaryMetadata(this.metadata, IS_TRUTHY), | ||
condition(this, false, (_: boolean) => true, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(expr: boolean) => Boolean(expr), false)
public isFalsy(): BooleanFunction { | ||
return new BooleanFunction( | ||
new UnaryMetadata(this.metadata, IS_FALSY), | ||
condition(this, false, (expr: boolean) => !Boolean(expr), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
9678886
to
15767df
Compare
Porter un point d'attention particulier sur les modifs dans doov.ts ; on est bien d'accord que les BooleanFunction retournent toutes un boolean ?