rust icon indicating copy to clipboard operation
rust copied to clipboard

Implement new Concept Exercise: iterators

Open workingjubilee opened this issue 5 years ago • 8 comments

This issue describes how to implement the iterator concept exercise for the Rust track.

Getting started

Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:

Please also watch the following video:

Goal

Iterators are one of Rust's more versatile linguistic abstractions, so it is not possible to cover in a single exercise. This exercise has only the goal of covering the foundations of Iterator so that advanced usage can be covered in detail.

Learning objectives

Student should be able to...

  • recognize some cases where they can use .iter()
  • use .next() to advance the iterator manually
  • use one Iterator method with a closure, such as fold, map, or filter
  • use fold or collect to produce a single value
  • recognize basic implications of iterator laziness (so a fold or collect is required)

Student may be able to...

  • recognize Iterator is as or more performant than for loops

Out of scope

  • zip, chain, flatten, and other multi-iterator methods
  • skip, step_by, take_while, and other selective iteration methods

Concepts

  • Iterator

Prerequisites

  • methods and traits
  • in particular method chaining
  • the collection in use (probably vec or String)
  • some awareness of what an expression actually does
  • some awareness of what a closure is like and/or higher-order functions
  • if using filter: booleans and predicates

Resources to refer to

Hints

After

Likely better for later exercises, but relevant:

Representer

This should require no special changes to the representer.

Analyzer

This should require no special changes to the analyzer.

Implementing

See our implementation guide for guidance. . You may want to make use of boil_exercise.sh in the concept directory

Help

If you have any questions while implementing the exercise, please post the questions as comments in this issue.

workingjubilee avatar Apr 09 '20 05:04 workingjubilee

Found Tim McNamara's video tutorial which would be a great intermediate / continue learning post: https://tim.mcnamara.nz/post/618982870485172224/rust-iteration.

ghost avatar Jan 06 '21 21:01 ghost

Would luhn work well for this concept?

personally I would change the spec to allow single character numbers so that the implementation is slightly nicer when done as a single expression.

gilescope avatar Jan 20 '21 11:01 gilescope

@gilescope I feel we'll only know by trying! So if you are up for it, give it a whirl! For concept exercises I am unsure of how it will go and don't want to waste time on Exercism specific metadata, I have used a draft PR with a single example.rs. exercism/v3#3061 is an example.

ghost avatar Jan 22 '21 16:01 ghost

Actually I think maybe we should aim for a functional rust track where each answer is expected to be one expression and the tasks getting gradually harder as we introduce different things. For example lune should be targeting as a showcase for try_fold.

gilescope avatar Jan 23 '21 17:01 gilescope

@coriolinus I wouldn't mind working on this next (both the concept and concept exercise). But it seems like we should have covered the trait concept before building out iterator? Do you have an opinion what would be the concepts/concept exercises that should be ready before working on iterator? I'd be happy to work on those first and eventually cover this issue.

nahuakang avatar May 05 '22 14:05 nahuakang

It looks to me as though this concept is about using iterators, not defining them. I'm not sure how useful it would be to require knowledge of traits first. My instinct is that it should be OK to have this concept depend solely on the methods concept, and then have students implement a generator (via the Iterator trait) as part of the traits concept, which naturally would then come after this one.

We have to mention in the concept documentation that it is a trait, but I think it's OK to defer further explanation for later.

On Thu, May 5, 2022, 16:35 Nahua @.***> wrote:

@coriolinus https://github.com/coriolinus I wouldn't mind working on this next (both the concept and concept exercise). But it seems like we should have covered the trait concept before building out iterator? Do you have an opinion what would be the concepts/concept exercises that should be ready before working on iterator? I'd be happy to work on those first and eventually cover this issue.

— Reply to this email directly, view it on GitHub https://github.com/exercism/rust/issues/1065#issuecomment-1118631214, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3V4TXCYNJNE4VX53V7GPLVIPMCJANCNFSM4WXPOFKA . You are receiving this because you were mentioned.Message ID: @.***>

coriolinus avatar May 05 '22 14:05 coriolinus

Happy to claim this if you assign it to me. Shall I also create an issue for the trait concept exercise?

nahuakang avatar May 05 '22 15:05 nahuakang

Sounds good! Please do create a traits concept issue.

coriolinus avatar May 05 '22 16:05 coriolinus

After several failed attempts to create a high-quality syllabus, I believe any future attempts will have to do their own design work from scratch.

senekor avatar Sep 19 '23 07:09 senekor