Comments (8)
Hi @tomvandenberge, looks like that part of documentation is outdated because we are not validating it with Ank. Our mistake. fx
was moved to work over the companion object of the type, that is Option.fx {}
and Either.fx { }
.
This is what would work now:
Option
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.extensions.fx
object Lettuce
object Knife
object Salad
fun takeFoodFromRefrigerator(): Option<Lettuce> = None
fun getKnife(): Option<Knife> = None
fun prepare(tool: Knife, ingredient: Lettuce): Option<Salad> = Some(Salad)
fun prepareLunchOption(): Option<Salad> =
Option.fx {
val lettuce = takeFoodFromRefrigerator().bind()
val knife = getKnife().bind()
val salad = prepare(knife, lettuce).bind()
salad
}
Either
import arrow.core.Either
import arrow.core.Left
import arrow.core.Right
import arrow.core.extensions.fx
object Lettuce
object Knife
object Salad
typealias NastyLettuce = CookingException.LettuceIsRotten
typealias KnifeIsDull = CookingException.KnifeNeedsSharpening
typealias InsufficientAmountOfLettuce = CookingException.InsufficientAmount
sealed class CookingException {
object LettuceIsRotten: CookingException()
object KnifeNeedsSharpening: CookingException()
data class InsufficientAmount(val quantityInGrams : Int): CookingException()
}
fun takeFoodFromRefrigerator(): Either<NastyLettuce, Lettuce> = Right(Lettuce)
fun getKnife(): Either<KnifeIsDull, Knife> = Right(Knife)
fun lunch(knife: Knife, food: Lettuce): Either<InsufficientAmountOfLettuce, Salad> = Left(InsufficientAmountOfLettuce(5))
fun prepareEither(): Either<CookingException, Salad> =
Either.fx {
val lettuce = takeFoodFromRefrigerator().bind()
val knife = getKnife().bind()
val salad = lunch(knife, lettuce).bind()
salad
}
I've checked and when using it like this, autocomplete works seamlessly. I'm using Arrow 0.10.5.
I you want to help on fixing docs you can find those here. We'd need to adapt those snippets to match my examples here and move all those from to be kotlin:ank
blocks instead of simply kotlin
, that's what enables our Ank processor to validate doc snippets.
Sorry for the inconvenience, let me know if this is clear enough 👍
from arrow-core.
Thanks for raising this issue, @tomvandenberge. I've seen that the example that is using arrow.core.extensions.option.monad.binding
doesn't include the ank
rule so it's not being validated when building the documentation.
We're going to fix it and maybe we could create another issue to review the ank
rule for all the code snippets because it's missing in other cases 👍
Thanks again!
from arrow-core.
In the meantime, what do I need to change to make it work?
Thanks
from arrow-core.
Hi! It seems there is a reason why it doesn't include the ank
rule and there are pending tasks to make it work: arrow-kt/arrow#2097 Let's see if someone else can provide more info about it cc: @pakoito
from arrow-core.
hehehe monad.binding
predates fx
and the snippets aren't updated nor checked
In the meantime, what do I need to change to make it work?
Load them up in a project with arrow-core, and follow IntelliJ's suggestions about imports for fx
. Good chance it'll be just Either.fx
because the snippet is for a concrete instance.
Then open a PR to the docs with the fix :D
from arrow-core.
You're making this really hard. As I said in my first message, it doesn't come up with any suggestions. And, yes, my project imports arrow-core (0.10.4). Could you please tell me what to import?
from arrow-core.
Sorry, I missed your edit on your response. Either.fx
doesn't work: Function invocation 'fx(...)' expected
.
A working code sample, including imports would be great.
from arrow-core.
Created #96 to fix them. Thanks @JorgeCastilloPrz 🙌
from arrow-core.
Related Issues (20)
- BUILD: error when integrating 'Deprecate @higherkind & @extension for TupleN (#292)' with the rest of Arrow libraries
- BUILD: error when integrating 'Deprecate extension methods for NonEmptyList (#304)' with the rest of Arrow libraries
- BUILD: error when merging 'Deprecate extensions methods for Set and SetK (#299)' on master branch
- DOC: error when integrating 'Fix incorrect package new instances (#306)' with the rest of Arrow libraries
- BUILD: error when integrating 'CU-cew8k0 Remove Deprecated `Id<A>` data type. (#291)' with the rest of Arrow libraries
- BUILD: error when merging 'CU-cn28ya Deprecate @higherkind & @extension for Ior (#317)' on master branch
- BUILD: error when integrating 'Deprecates Kind and its associated type class types. (#281)' with the rest of Arrow libraries
- BUILD: error when integrating 'Deprecates Kind and its associated type class types. (#281)' with the rest of Arrow libraries
- BUILD: error when integrating 'Deprecate Show (#321)' with the rest of Arrow libraries
- BUILD: error when merging 'Deprecate Eq (#322)' on master branch HOT 1
- BUILD: error when integrating 'CU-cn24b4 Remove extension and higherkind annotations for Const (#315)' with the rest of Arrow libraries
- BUILD: error when integrating 'CU-cn24b4 Remove extension and higherkind annotations for Const (#315)' with the rest of Arrow libraries
- BUILD: error when integrating 'Fix typo in deprecation messages (#335)' with the rest of Arrow libraries
- BUILD: error when merging 'Unify syntax for extracting inner values (#338)' on master branch
- BUILD: error when integrating 'Deprecate Hash (#337)' with the rest of Arrow libraries
- DOC: error when merging 'Make memoization compatible with MPP (#331)' on master branch HOT 1
- BUILD: error when merging 'Make memoization compatible with MPP (#331)' on master branch HOT 2
- BUILD: error when merging 'Make memoization compatible with MPP (#331)' on master branch
- BUILD: error when merging 'Make memoization compatible with MPP (#331)' on master branch HOT 2
- BUILD: error when integrating 'Publication: disable checksums for maven-metadata.xml (#354)' with the rest of Arrow libraries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arrow-core.