Skip to content

Commit

Permalink
Made OpRunningOp have initial value as a parameter so that RUNNING_MU…
Browse files Browse the repository at this point in the history
…L doesn't multiply everything by 0.
  • Loading branch information
Talia-12 committed Nov 21, 2022
1 parent f49e16d commit f1cba24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ object Patterns {
@JvmField
val FACTORIAL = make(HexPattern.fromAngles("wawdedwaw", HexDir.SOUTH_EAST), modLoc("factorial"), OpFactorial)
@JvmField
val RUNNING_SUM = make(HexPattern.fromAngles("aea", HexDir.WEST), modLoc("running/sum"), OpRunningOp{ running, iota ->
val RUNNING_SUM = make(HexPattern.fromAngles("aea", HexDir.WEST), modLoc("running/sum"), OpRunningOp (0.0)
{ running, iota ->
running + ((iota as? DoubleIota)?.double ?: throw OpRunningOp.InvalidIotaException("list.double"))
})
@JvmField
val RUNNING_MUL = make(HexPattern.fromAngles("qaawaaq", HexDir.NORTH_EAST), modLoc("running/mul"), OpRunningOp{ running, iota ->
val RUNNING_MUL = make(HexPattern.fromAngles("qaawaaq", HexDir.NORTH_EAST), modLoc("running/mul"), OpRunningOp (1.0)
{ running, iota ->
running * ((iota as? DoubleIota)?.double ?: throw OpRunningOp.InvalidIotaException("list.double"))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import ram.talia.hexal.api.reductions

class OpRunningOp(private val operator: (Double, Iota) -> Double) : ConstMediaAction {
class OpRunningOp(private val initial: Double, private val operator: (Double, Iota) -> Double) : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
try {
return args.getList(0, argc).reductions(0.0, operator).map { DoubleIota(it) }.toList().asActionResult
return args.getList(0, argc).reductions(initial, operator).map { DoubleIota(it) }.toList().asActionResult
} catch (e: InvalidIotaException) {
throw MishapInvalidIota.ofType(args[0], 0, e.expectedType)
}
Expand Down

0 comments on commit f1cba24

Please sign in to comment.