Giter VIP home page Giter VIP logo

Comments (8)

JorgeCastilloPrz avatar JorgeCastilloPrz commented on June 2, 2024 3

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.

rachelcarmena avatar rachelcarmena commented on June 2, 2024

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.

tomvandenberge avatar tomvandenberge commented on June 2, 2024

In the meantime, what do I need to change to make it work?

Thanks

from arrow-core.

rachelcarmena avatar rachelcarmena commented on June 2, 2024

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.

pakoito avatar pakoito commented on June 2, 2024

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.

tomvandenberge avatar tomvandenberge commented on June 2, 2024

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.

tomvandenberge avatar tomvandenberge commented on June 2, 2024

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.

rachelcarmena avatar rachelcarmena commented on June 2, 2024

Created #96 to fix them. Thanks @JorgeCastilloPrz 🙌

from arrow-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.