Skip to content

Commit 069aca4

Browse files
committed
refactor(library/Range): moves validation to factory in DiscreteRange
1 parent c33a48a commit 069aca4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/library/Range/DiscreteRange.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ class DiscreteRange
1414
upperBound,
1515
);
1616

17-
if (
18-
stepSize < 0
19-
) return Attempt.abandon('Step size must be positive');
20-
21-
const overstep = this.width % stepSize;
22-
23-
if (
24-
overstep !== 0
25-
) return Attempt.abandon('Step size must fit evenly into the range');
26-
2717
this.stepSize = stepSize;
2818
}
2919

@@ -43,6 +33,16 @@ class DiscreteRange
4333
to : givenUpperBound,
4434
});
4535

36+
if (
37+
givenStepSize < 0
38+
) return Attempt.abandon('Step size must be positive');
39+
40+
const overstep = validRange.width % givenStepSize;
41+
42+
if (
43+
overstep !== 0
44+
) return Attempt.abandon('Step size must fit evenly into the range');
45+
4646
const validDiscreteRange = new this(
4747
validRange.lowerBound,
4848
validRange.upperBound,

0 commit comments

Comments
 (0)