-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ProcessingUnit trait for readability
- Loading branch information
Kota Mizushima
committed
Dec 27, 2023
1 parent
5e759be
commit bb18c3f
Showing
6 changed files
with
30 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package onion.compiler | ||
|
||
trait Processor[A, B] {self => | ||
type Environment | ||
def newEnvironment(source: A): Environment | ||
protected def processBody(source: A, environment: Environment): B | ||
protected def preprocess(source: A): Unit = {} | ||
protected def postprocess(source: A, result: B): Unit = {} | ||
|
||
final def process(source: A): B = { | ||
preprocess(source) | ||
val result = processBody(source, newEnvironment(source)) | ||
postprocess(source, result) | ||
result | ||
} | ||
|
||
def andThen[C](nextUnit: Processor[B, C]): Processor[A, C] = new Processor[A, C] { | ||
type Environment = Null | ||
def newEnvironment(source: A): Environment = null | ||
def processBody(source: A, environment: Null): C = nextUnit.process(self.process(source)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters