Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pressMenu action to DSL #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sealed class GestureDSL<out A> : HK<GestureDSL.F, A> {
data class Wait<R>(val condition: SearchCondition<R>, val timeout: Long) : GestureDSL<R>()
data class FindObject(val selector: UiSelector) : GestureDSL<UiObject>()
data class WithDevice<out A>(val f: (UiDevice) -> A) : GestureDSL<A>()
object PressMenu : GestureDSL<Boolean>()

companion object : FreeMonad<GestureDSL.F>

Expand All @@ -27,6 +28,7 @@ class SafeInterpreter<F>(val M: MonadError<F, Throwable>, val device: UiDevice)
is GestureDSL.Wait<*> -> M.pure(device.wait(g.condition, g.timeout))
is GestureDSL.FindObject -> M.pure(device.findObject(g.selector))
is GestureDSL.WithDevice<*> -> M.pure(g.f(device))
is GestureDSL.PressMenu -> M.pure(device.pressMenu())
} as HK<F, A>
}
}
Expand All @@ -51,6 +53,7 @@ fun pressHome(): DSLAction<Boolean> = Free.liftF(GestureDSL.PressHome)
fun <R> wait(condition: SearchCondition<R>, timeout: Long): DSLAction<R> = Free.liftF(GestureDSL.Wait(condition, timeout))
fun findObject(selector: UiSelector): DSLAction<UiObject> = Free.liftF(GestureDSL.FindObject(selector))
fun <A> withDevice(f: (UiDevice) -> A): DSLAction<A> = Free.liftF(GestureDSL.WithDevice(f))
fun pressMenu(): DSLAction<Boolean> = Free.liftF(GestureDSL.PressMenu)

fun <A> Free<GestureDSL.F, A>.run(device: UiDevice): Try<A> =
this.foldMap(SafeInterpreter(Try, device), Try).ev()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ object GestureDSLExamples {
/**
* compose multiple actions independently regardless of return types
*/
fun independentActionsWorkflow(): DSLAction<Tuple4<Boolean, UiObject, UiObject, UiObject>> =
fun independentActionsWorkflow(): DSLAction<Tuple5<Boolean, Boolean, UiObject, UiObject, UiObject>> =
GestureDSL.tupled(
pressHome(),
pressMenu(),
findObject(UiSelector().description("1")),
findObject(UiSelector().description("2")),
findObject(UiSelector().description("3"))).ev()
Expand Down