Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-adam committed May 15, 2024
1 parent 96cc29f commit 9294ae5
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package pl.writeonly.catculator.core.calculators.lazyk

import cats.Applicative
import pl.writeonly.catculator.core.adt.calculus.Combinator
import pl.writeonly.catculator.core.adt.calculus.Combinator._
import pl.writeonly.catculator.core.adt.calculus.Combinator.*
import pl.writeonly.catculator.core.adt.calculus.Lambda
import pl.writeonly.catculator.core.adt.tree.BinaryTree
import pl.writeonly.catculator.core.adt.tree.BinaryTree._
import pl.writeonly.catculator.core.calculators.lazyk.ADT._
import pl.writeonly.catculator.core.adt.tree.BinaryTree.*
import pl.writeonly.catculator.core.calculators.lazyk.ADT.*
import pl.writeonly.catculator.core.reducers.LambdaReducer.toCombinatorBT
import spire.math.Natural

import scala.util.Right
Expand All @@ -15,12 +18,7 @@ object Reducer {
case x => Right(x)
}

def applyM(fM: ADTBTSafe, xM: ADTBTSafe): ADTBTSafe =
for
f <- fM
x <- xM
r <- apply(f, x)
yield r
def applyM(f: ADTBTSafe, x: ADTBTSafe): ADTBTSafe = Applicative[Safe[*]].map2(f, x)(apply).flatten

def flippedApply(x: ADTBT, y: ADTBT): ADTBTSafe = apply(y, x)

Expand All @@ -36,5 +34,4 @@ object Reducer {
case Leaf(ADT.Num(x)) => Right(Leaf(ADT.Num(x + Natural.one)))
case _ => Left(s"attempted to apply inc to a non-number $x")
}

}

0 comments on commit 9294ae5

Please sign in to comment.