objcio / functional-swift

Issue repository for the Functional Swift book
http://www.objc.io/books/fpinswift
927 stars 133 forks source link

Upgraded reduce condition on `String` implementation of `Smaller` protocol #113

Closed mariopavlovic closed 8 years ago

mariopavlovic commented 8 years ago

We used to implement Smaller protocol on String so that it returns a new string, without a first character, for all non-empty strings. This would reduce all strings to an empty string when running smaller function repeatedly. New implementation defines smallest String as a single character string, which prevents the occurrence of the empty string as a result of smaller function.

Example: Before running smaller repeatedly on "Hello" string would output "ello", "llo", "lo", "o", "". Now running smaller repeatedly on "Hello" string would output "ello", "llo", "lo", "o".

Note: This PR is just a suggestion, as it's a small change and it would require update of the book feel free to backlog it or reject

mariopavlovic commented 8 years ago

Just realized that maybe you want to check for empty strings? As this is something that would be part of the "fuller test suit"?

chriseidhof commented 8 years ago

Yes, we absolutely do want to check for empty strings. There are many cases in which this could break the property under test.