5 kyu

Java Functional Programming (Part 4: Row Row Row Your Boat, Gently Down the...)

Description
Loading description...
Streams
Functional Programming
Algorithms
View
AllIssues2QuestionsSuggestions1Show Resolved
  • Please sign in or sign up to leave a comment.
  • shoplucaaa Avatar

    how is "the guide that tell us to do everything" actually making the task at least 5 times difficult than the original task

    I have completed this, and still want this one to be permantly deleted

  • farmac Avatar

    Very nice kata!

  • telnetdoogie Avatar

    This took me a really long time (almost the whole day) and I struggled a lot. I found the previous exercises in the series fairly simple but this one I really struggled with. I plodded on, searching online for various things and I seemed to be progressing. I started by commenting out all but the first / simplest test, and worked to get that working. Once it did, I uncommented the next... now I have to deal with the iteration on creation... then I revealed the next one etc... that definitely made it more manageable... but then when submitting, I hit the createFilter tests... I swear, it simply wasn't clear to me how that was supposed to work at all. At this point I was guessing and it seemed like no combination of logic would get my tests to pass. Eventually I did 'reveal solutions' which meant that I didn't get credit for completion, but I actually learned that I was super close and it was simpler than I thought. I would have like to have seen the createFilter tests in the main Kata versus hidden until submission.

    I got through, and I think I learned something about streams and conversions etc., but I have to be honest I don't think I'll retain what I took from creating the custom functions or predicate... They still seem obtuse to me and when I look at the code that was created as a result, it doesn't necessarily make sense to me why I'd use these.

    Really enjoyed the series, thank you! This one was tough for me.

  • Nanor Avatar

    I don't get it. For what I need howMany() method? Ok. I understood that I need to create stream from init string, then with map function, transform n times the curve, and the with I need to remove all letters a and b, but I didn't get how I should use method howMany() ?

  • Voile Avatar

    Approved

  • rbitard Avatar

    The filter part wasn't clear (for me), you should have made a test case for that I had to rewrite it since my filter wasn't working when submitting

  • Porcupine96 Avatar

    Ok... I really don't get it - when the IntPredicate createFilter produces should return true? I've tried like all possible combinations...

    For me the most logical would be: c -> c != filterWhat || keep;

    • Azuaron Avatar

      You need to think through what needs to happen when on keep == true vs keep == false. If keep == true, you still only want to keep the specific character coming in from filterWhat.

    • hugomfcruz Avatar

      The description of this method is not ideal and it's possible to pass all the "curve" tests while failing the "createFilter" tests.

      The "trick" is to know that a filter with keep either removes ONLY one character or keeps ONLY one character. This last bit was the one that forced me to reverse engineer the expected behaviour to satisfy the tests.

  • SorenTheBrave Avatar

    This comment has been hidden.

    • Azuaron Avatar

      Your stream should definitely be stateless. This does not mean that values inside the stream shouldn't change (they should, that's what map is for), but they must not change (or, ideally, even rely upon) values outside the stream*. Additionally, once a stream has been used (IntStream output, in your case), it can't be used again. If you look at the method signature for IntStream::mapToObject, you'll notice it returns a new Stream. If you want to perform additional functions upon your stream, this new stream is the one you need to act upon.

      * Depending on what you're doing, you may want something like an AtomicInteger for counting, but you must remember it can be acted upon by multiple instances of the stream in a parallel environment (if you aren't synchronized). When it comes to lambdas, if something can be done stateless, it should be done stateless.

  • pwnfooj716 Avatar

    The use of Strings throughout the program rather than IntStreams prevents the use of the "flatMap" function in the IntStream class (because mapFunction must return an IntStream, not a String). This means the programmer must essentially write their own "flatMap" function to use Strings which is unnecessary. Also, converting from an IntStream back to a String is a pain and it unneccesary in the case of the creation of the dragon curve. Just use IntStreams instead of Strings and this Kata is pretty good.

    • Azuaron Avatar

      This is the last kata in a series, and, as such, it makes you use all the things you learned in the series. Part of that is converting from a String into an IntStream and back again (a common task in Java streaming). There's no "essentially" about the programmer writing their own flatMap function; that's a specifically defined part of the kata.

      Further, it's essentially a translation of another kata of the Dragon's Curve (http://www.codewars.com/kata/dragons-curve), but forces the use of Java streams. As such, it keeps to the contract of that kata as much as possible, which is also heavily reliant on String manipulation and String out.

      Finally, a stylistic complaint is a "Suggestion", not an "Issue".

      Issue marked resolved by Azuaron 10 years ago
    • pwnfooj716 Avatar

      Ok fair enough. And yeah i shouldn't have marked it as an issue. Sorry about that.

    • pwnfooj716 Avatar

      Im just not big on reinventing the wheel, but you're right there is nothing wrong with the Kata.

  • jcsahnwaldt Avatar

    I love the idea of applying a mapping multiple times. Good idea! But I don't like the way the tests try to force me to solve the kata in a very specific way.