New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Array[String val] contains using result of string.substring
#2759
Comments
By default, the The default value is a lambda that does identity comparison (i.e. In your case, you can provide a custom lambda for structural equality in your code: let predicate': {(String val, String val): Bool} = {(l: String val, r: String val): Bool => l == r })
imageEndings.contains(ending where predicate = predicate').string() The fact that the first two calls to Personally, considering how identity comparison should work, the first two calls to |
I'm going to call this a bug. However, its a documentation bug, Array.contains should explain the predicate. It should explain that "matching" is done based on identity and it should give examples of how to do something like what @sirscratchalot wanted to do. |
Would following be considered good pony form? The types of l and r are inferred and not having the "where" clause? actor Main
new create(env: Env) =>
let imageEndings:Array[String val] val = [".jpg";".png";".bmp";".gif"]
let endSubStr:String val = ".png".substring(0, 4)
let resultEndSubStr=imageEndings.contains(endSubStr, {(l, r): Bool => l == r})
env.out.print("resultEndSubStr=" + resultEndSubStr.string())
// Prints ResultEndSubStr=true |
other than the "not standard library" formatting, yes, that is how you would want to use contains in this situation @winksaville. |
From the style guide for lambda it looks like I need to add a space before the trailing brace to make it standard, anything else? let resultEndSubStr=imageEndings.contains(endSubStr, {(l, r): Bool => l == r }) |
space before and after the snake case for variables. |
Txs, so: let result_end_sub_str = image_endings.contains(end_sub_str, {(l, r): Bool => l == r }) |
yup |
Hello, I've hit a wall with Array.contains when calling with the result of a
String.substring
operation.This returns
false
even when equivalent calls using equivalent strings returntrue
.Here is a quick code example with printouts as comments, the unexpected behaviour comes in the final print statement :
Expected behaviour would be a final print out of:
Ending .png 4 true
Originally brought this up on the freenode chat and was asked to create an issue for this. Hopefully I interpreted this correctly and came to the right place.
The text was updated successfully, but these errors were encountered: