-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d844486
commit 96cc29f
Showing
5 changed files
with
12 additions
and
17 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 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
11 changes: 5 additions & 6 deletions
11
catculator-core/src/main/scala/pl/writeonly/catculator/core/reducers/LambdaReducer.scala
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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package pl.writeonly.catculator.core.reducers | ||
|
||
import cats.Applicative | ||
import cats.implicits._ | ||
import pl.writeonly.catculator.core.adt.calculus.Combinator._ | ||
import pl.writeonly.catculator.core.adt.calculus.Lambda | ||
import pl.writeonly.catculator.core.adt.calculus.Lambda._ | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree._ | ||
|
||
object LambdaReducer { | ||
def toCombinatorBT(l: Lambda): Either[Lambda, CombinatorBT] = l match { | ||
case Com(c) => Right(Leaf(c)) | ||
case App(f, x) => for { | ||
fc <- toCombinatorBT(f) | ||
xc <- toCombinatorBT(x) | ||
} yield Node(fc, xc) | ||
case _ => Left(l) | ||
case Com(c) => Right(Leaf(c)) | ||
case App(f, x) => Applicative[Either[Lambda, *]].map2(toCombinatorBT(f), toCombinatorBT(x))(Node.apply) | ||
case _ => Left(l) | ||
} | ||
} |
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