Skip to content

add strain#96

Merged
glennj merged 2 commits intoexercism:mainfrom
BNAndras:add-strain
Mar 18, 2026
Merged

add strain#96
glennj merged 2 commits intoexercism:mainfrom
BNAndras:add-strain

Conversation

@BNAndras
Copy link
Member

@BNAndras BNAndras commented Mar 9, 2026

No description provided.

@glennj
Copy link
Contributor

glennj commented Mar 17, 2026

First, apologies for taking so long. I wasn't actually watching the repo so I didn't get notified about your PRs

Second, isn't this exercise generally deprecated in favour of list-ops?

Nevertheless, I'll review and merge when ready.

Comment on lines +40 to +43
pending 'keeps strings', ->
result = Strain.keep {'apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zealot'}, (x) -> starts_with x, 'z'
expected = {'zebra', 'zombies', 'zealot'}
assert.are.same expected, result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more readable like:

Suggested change
pending 'keeps strings', ->
result = Strain.keep {'apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zealot'}, (x) -> starts_with x, 'z'
expected = {'zebra', 'zombies', 'zealot'}
assert.are.same expected, result
pending 'keeps strings', ->
list = {'apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zealot'}
predicate = (x) -> starts_with x, 'z'
result = Strain.keep list, predicate
expected = {'zebra', 'zombies', 'zealot'}
assert.are.same expected, result

and the prediate variable can be more descriptive, like

predicate = (str) -> starts_with str, 'z'
-- or
predicate = (sublist) -> contains sublist, 5
-- or
predicate = (_) -> true -- always true

I'll look at the generator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I definitely agree. A little deviance from the problem specs names is fine if it improves readability.

@glennj
Copy link
Contributor

glennj commented Mar 18, 2026

First, apologies for taking so long. I wasn't actually watching the repo so I didn't get notified about your PRs

And I was coming here thinking about what new exercises to add, now that I've given you a turn ;)

@BNAndras
Copy link
Member Author

Second, isn't this exercise generally deprecated in favour of list-ops?

You might be thinking of accumulate, which is deprecated in favor of list-ops. Only 17 tracks have that exercise still available while a total of 55 tracks have List Ops. Strain is present on 44 tracks and isn't deprecated. The filter functionality in List Ops is pretty similar to the keep functionality in Strain though, and overall List Ops is more interesting I think. However, Strain might still be useful as a simpler exercise leading into List Ops.

@glennj glennj merged commit 34f38d4 into exercism:main Mar 18, 2026
3 checks passed
glennj pushed a commit to glennj/exercism-moonscript that referenced this pull request Mar 18, 2026
* add `strain`

* Update spec generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants