From 6e6ac9ad01e5b856fc5664d721fa5e3fae94a533 Mon Sep 17 00:00:00 2001 From: AdrianRaFo Date: Wed, 21 Mar 2018 22:13:37 +0100 Subject: [PATCH] Ap docs --- .../docs/docs/datatypes/kleisli/README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/docs/arrow-docs/docs/docs/datatypes/kleisli/README.md b/modules/docs/arrow-docs/docs/docs/datatypes/kleisli/README.md index 80cc50803c6..eafa1515ce6 100644 --- a/modules/docs/arrow-docs/docs/docs/datatypes/kleisli/README.md +++ b/modules/docs/arrow-docs/docs/docs/datatypes/kleisli/README.md @@ -14,7 +14,7 @@ we want to do a safe conversion like this: ```kotlin:ank:silent import arrow.core.* -import arrow.data.* +import arrow.data.Kleisli val optionIntKleisli = Kleisli { str: String -> if (str.toCharArray().all { it.isDigit() }) Some(str.toInt()) else None @@ -43,6 +43,21 @@ This function allows doing a conversion inside the Kleisli to the original input optionIntKleisli.local { optStr :Option -> optStr.getOrElse { "0" } }.run(None) ``` +#### Ap +The `ap` function transform the `Kleisli` into another `Kleisli` with a function as a output value. + +```kotlin:ank +import arrow.data.fix + +val intToDouble = {number:Int -> number.toDouble()} + +val optionIntDoubleKleisli = Kleisli { str: String -> + if (str.toCharArray().all { it.isDigit() }) Some(intToDouble) else None +} + +optionIntKleisli.ap(optionIntDoubleKleisli,Option.applicative()).fix().run("1") +``` + #### Map The `map` function transform the `Kleisli` output value.