5 kyu

Lazy evaluation

1,792 of 1,795surtich
Description
Loading description...
Functional Programming
  • Please sign in or sign up to leave a comment.
  • trashy_incel Avatar

    should use more recent JavaScript (classes, rest parameters). i'd do it, but regular users cannot edit katas anymore ...

    • hobovsky Avatar

      Preferred way to fix a kata would be to fork it (you know how to fix a current state of a kata, do you?), and announce the fork as usual with a suggestion. Then it can be approved as any other fork.

      Since forking kata has been available, it's not really necessary to edit approved kata directly anymore (unless you think otherwise?)

    • trashy_incel Avatar

      The difference is that editing fixes the kata now, while forks can stay unapproved forever, because reviewing takes time and motivation, and is only possible for users who already solved the kata.

      I used to upgrade language versions and improve assertion messages from time to time after solving a kata, now I dont think I will bother doing that anymore.

      I understand that the change has probably been implemented to prevent malicious or confused users from ruining katas, and it's a valid reason, but on the other hand it can delay fixes and upgrades for a long time.

  • Ivanestver Avatar

    I guess there is some mistake in the last example in 'Test Reuse lazy filterNumbers + filterRange + max function' section. I understood it when I was exploring the output. I realized that it is as in the description, but the correct result is different. I mean, in the description '6' is received but in the example '1'. Can you fix it or explain me what I understood wrong?

    • ejini战神 Avatar

      Not a kata issue! The example in description uses a filterRange of 2 to 7 whereas the test case you're encountering one uses a filterRange of 1 to 3.

      Issue marked resolved by ejini战神 12 months ago
  • Blind4Basics Avatar
    • no sample tests
    • no random tests
  • Sler Avatar

    I believe one of the test cases might be wrong. Test Reuse lazy filterNumbers + filterRange + max function, 2nd one. My function passes every one except for this one, here are the results for each stage: [Function: filterNumbers] arguments - [ 1, '3', [ 2 ], {}, 4, 2, 1, 8, 6, [], '7', -1, { v: 5 }, 4 ] result - [ 1, 4, 2, 1, 8, 6, -1, 4 ], [Function: filterRange] arguments - [ 1, 3, 1, 4, 2, 1, 4, 2, 1, 8, 6, -1, 4 ] result [ 1, 2, 1, 2, 1 ], [Function: max] arguments - [ 1, 2, 1, 2, 1, 2, 1 ] result 2 Everything seems correct but for some reason the expected output in the last one is 1, not 2. Might there be a mistake here?

    • trashy_incel Avatar

      as the name of the tests imply, your solution has to be reusable, i.e. invoke() should behave correctly when called several times on the same Lazy object

      Issue marked resolved by trashy_incel 2 years ago
  • MarcoPolouuu Avatar

    All tests are running successfully, but after one particular an error is thrown: 'Test Reuse lazy filterNumbers + filterRange + max function'. So what's the idea of that test, and why an error is thrown despite test value and value from solution are equal?

  • EFI131 Avatar

    Thanks for the awesome kata! I learned a lo tfrom it:)

  • user2713389 Avatar

    Specify the invoike 'target' parameter will always be an array

  • kesheshyan Avatar

    Great kata, but why do you pass a list of arguments into the invoke function as array .invoke([arg1, arg2 ...])? I guess it would be better to pass arguments as usual .invoke(arg1, arg2 ...)

    • surtich Avatar

      Maybe I could have done it like you are suggesting. I think now it would be undesirable because it would require a change to refactor the solution to twelve people. Thanks for the suggestion.

  • josex2r Avatar

    This comment has been hidden.

  • wthit56 Avatar

    It's kind of unclear what behaviour is expected from the description. I had to figure it out from the example code and test errors. Ideally, a description should describe the problem in full.

    Also, I'm not enitrely sure this is even lazy evaluation. The point of lazy evaluation is so that functions can be combined and used in the middle of a loop, instead of iterating over everything mutliple times, or creating unnecessary arrays and such. The example code provided makes this impossible and so, while I completed the kata, I didn't really do any of the lazy-eval type stuff.

    • surtich Avatar

      Thanks, wthit56, for your commet.

      I have tried to explain the description a little more.

      About what lazy evaluation means, I have used then explanation of Functional JavaScript book.

    • wthit56 Avatar

      I thinkt the problem is more what calls are made in qhat order and with what arguments from where. Below, I've added comments to show exactly how it should work; this might make things clearer.

      new Lazy()
        .add(filterNumbers)
        .add(filterRange, 2, 7)
        .add(max)
        .invoke([1, 8, 6, [], "7", -1, {v: 5}, 4]); // == 6
        
      /* Calls:
        filterNumbers(1, 8, 6, [], "7", -1, {v: 5}, 4) // == [1, 8, 6, -1, 4]
        //            ^------------------------------ from invoke
        filterRange(2, 7, 1, 8, 6, -1, 4) // == [6, 4]
        // from add ---^  ^------------- from previous result
        max(6, 4) // == 6
        //  ^--- from previous result
        
        Result from invoke: 6
        //                  ^ from last result
      */
      
    • surtich Avatar

      Thanks a lot. I have added your commet to the kata description.

    • wthit56 Avatar

      Seems like something's gone wrong in the copy. The commented lines are out of place and pointing at the wrong lines. @.@"

    • surtich Avatar

      My mistake. Sorry and thanks again!

    • wthit56 Avatar

      Cool. Happy to help ^^

    • qbolec Avatar

      I think that solutions which use an array internally to store functions, and modify this array on add(), miss the point of reusability. In my opinion reusability is achieved when add() returns a new instance, without altering the previous one, so both can be used. I'd suggest to add a test which tests for reusability, something like: var smallNumbersOnly = new Lazy().add(filterNumbers).add(filterRange, 2, 7); var maxNumber = smallNumbersOnly.add(max); smallNumbersOnly.invoke([1,8,"6",4,7]) == [4,7] maxNumber.invoke([1,8,"6",4,7]) == 7

    • wthit56 Avatar

      I know what you're saying, but it seems like that wasn't the intent of the original kata. Maybe the author could reword things to be clearer on what he means by "reusability."