Clojure

Add clojure.string functions for portability to ClojureScript

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.8
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

Proposed clojure.string fn java.lang.String method
index-of indexOf
last-index-of lastIndexOf
starts-with? startsWith
ends-with? endsWith
includes? contains

Patch:

  • clj-1449-7.patch - uses nil to indicate not-found in index-of

Performance: Tested the following with criterium for execution mean time (all times in ns).

Java Clojure Java Clojure (-4 patch) Clojure (-6 patch)
(.indexOf "banana" "n") (clojure.string/index-of "banana" "n") 8.70 9.03 9.27
(.indexOf "banana" "n" 1) (clojure.string/index-of "banana" "n" 1) 7.29 7.61 7.66
(.indexOf "banana" (int \n)) (clojure.string/index-of "banana" \n) 5.34 6.20 6.20
(.indexOf "banana" (int \n) 1) (clojure.string/index-of "banana" \n 1) 5.38 6.19 6.24
(.startsWith "apple" "a") (clojure.string/starts-with? "apple" "a") 4.84 5.71 5.65
(.endsWith "apple" "e") (clojure.string/ends-with? "apple" "e") 4.82 5.68 5.70
(.contains "baked apple pie" "apple") (clojure.string/includes? "baked apple pie" "apple") 10.78 11.99 12.17

Screened by: Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

Note: In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.

  1. add_functions_to_strings.patch
    08/Jul/15 12:46 PM
    3 kB
    Nola Stowe
  2. add_functions_to_strings-2.patch
    14/Jul/15 8:55 PM
    4 kB
    Nola Stowe
  3. add_functions_to_strings-3.patch
    14/Jul/15 8:56 PM
    5 kB
    Nola Stowe
  4. add_functions_to_strings-4.patch
    14/Jul/15 9:56 PM
    5 kB
    Alex Miller
  5. add_functions_to_strings-5.patch
    26/Jul/15 9:28 AM
    5 kB
    Nola Stowe
  6. add_functions_to_strings-6.patch
    26/Jul/15 9:32 AM
    5 kB
    Alex Miller
  7. add_functions_to_strings-7.patch
    24/Aug/15 11:56 AM
    5 kB
    Nola Stowe
  8. clj-1449-more-v1.patch
    30/Aug/14 3:40 PM
    4 kB
    Andy Fingerhut

Activity

Alex Miller made changes -
Field Original Value New Value
Approval Triaged [ 10120 ]
Labels string
Alex Miller made changes -
Description While `clojure.string` wraps most of `java.lang.String`'s method, for some reason `startsWith` and `endsWith` were left out. Sure, in Java, one can use them fairly easy via the interop, but what if you're using ClojureScript (JavaScript's String class has not methods)? There's also the question of inconsistency, as the criteria by which String method were chosen for wrapping is unclear.

Should you approve this for inclusion I'd happily implement it.

P.S. The omission of `substring` is also a bit puzzling.
Add clojure.string/starts-with? and ends-with? similar to java.lang.String's startsWith/endsWith. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant.
Andy Fingerhut made changes -
Description Add clojure.string/starts-with? and ends-with? similar to java.lang.String's startsWith/endsWith. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant.
Add clojure.string/starts-with? ends-with? and contains?, similar to java.lang.String's startsWith/endsWith/contains. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant.
Summary Add starts-with? and ends-with? to clojure.string Add starts-with? ends-with? contains? to clojure.string
Andy Fingerhut made changes -
Attachment clj-1149-basic-v1.patch [ 13294 ]
Andy Fingerhut made changes -
Attachment clj-1449-more-v1.patch [ 13295 ]
Andy Fingerhut made changes -
Attachment clj-1449-basic-v1.patch [ 13316 ]
Andy Fingerhut made changes -
Attachment clj-1149-basic-v1.patch [ 13294 ]
Andy Fingerhut made changes -
Patch Code [ 10001 ]
Andy Fingerhut made changes -
Attachment clj-1449-basic-v1.patch [ 13316 ]
Andy Fingerhut made changes -
Description Add clojure.string/starts-with? ends-with? and contains?, similar to java.lang.String's startsWith/endsWith/contains. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant. Add clojure.string/starts-with? ends-with? and contains?, similar to java.lang.String's startsWith/endsWith/contains. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant.

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Priority Major [ 3 ] Critical [ 2 ]
Alex Miller made changes -
Description Add clojure.string/starts-with? ends-with? and contains?, similar to java.lang.String's startsWith/endsWith/contains. In addition to making these easier to find and use, this provides a place to add a portable ClojureScript variant.

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

|| java.lang.String method || Proposed clojure.string fn ||
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |
| indexOf | index-of |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
Summary Add starts-with? ends-with? contains? to clojure.string Add clojure.string functions for portability to ClojureScript
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

|| java.lang.String method || Proposed clojure.string fn ||
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |
| indexOf | index-of |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

|| java.lang.String method || Proposed clojure.string fn ||
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |
| indexOf | index-of |
| lastIndexOf | last-index-of |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

|| java.lang.String method || Proposed clojure.string fn ||
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |
| indexOf | index-of |
| lastIndexOf | last-index-of |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch*: clj-1449-more-v1.patch (draft version only -- a more serious contender would incorporate Alex Miller's comments from Dec 2 2014)
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch*: needed - needs to incorporate Alex Miller's comments from Dec 2 2014 and subsequent naming suggestions beyond existing patch
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch*: needed - needs to incorporate Alex Miller's comments from Dec 2 2014 and subsequent naming suggestions beyond existing patch
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch:* Patch clj-1449-more-v1.patch is a good start, but needs the following additional work:

1) Update function names per the description here.
2) Per the instructions at the top of the clojure.string ns, functions should take the broader CharSequence interface instead of String. Similar to existing clojure.string functions, you will need to provide a CharSequence implementation while also calling into the String functions when you actually have a String.
3) Consider return type hints - I'm not sure they're necessary here, but I would examine the bytecode in typical calling situations to see if it would be helpful.
4) The new functions need new tests.
5) Check performance implications of the new versions vs the old with a good tool (like criterium). It would be good to know what the difference in perf actually is - some hit is worth it for a portable target.
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| java.lang.String method || Proposed clojure.string fn ||
| indexOf | index-of |
| lastIndexOf | last-index-of |
| startsWith | starts-with? |
| endsWith | ends-with? |
| contains | includes? |

*Patch:* Patch clj-1449-more-v1.patch is a good start, but needs the following additional work:

1) Update function names per the description here.
2) Per the instructions at the top of the clojure.string ns, functions should take the broader CharSequence interface instead of String. Similar to existing clojure.string functions, you will need to provide a CharSequence implementation while also calling into the String functions when you actually have a String.
3) Consider return type hints - I'm not sure they're necessary here, but I would examine the bytecode in typical calling situations to see if it would be helpful.
4) The new functions need new tests.
5) Check performance implications of the new versions vs the old with a good tool (like criterium). It would be good to know what the difference in perf actually is - some hit is worth it for a portable target.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* Patch clj-1449-more-v1.patch is a good start, but needs the following additional work:

1) Update function names per the description here.
2) Per the instructions at the top of the clojure.string ns, functions should take the broader CharSequence interface instead of String. Similar to existing clojure.string functions, you will need to provide a CharSequence implementation while also calling into the String functions when you actually have a String.
3) Consider return type hints - I'm not sure they're necessary here, but I would examine the bytecode in typical calling situations to see if it would be helpful.
4) The new functions need new tests.
5) Check performance implications of the new versions vs the old with a good tool (like criterium). It would be good to know what the difference in perf actually is - some hit is worth it for a portable target.
Alex Miller made changes -
Assignee Nola Stowe [ rubygeek ]
Nola Stowe made changes -
Attachment add_functions_to_strings.patch [ 14311 ]
Nola Stowe made changes -
Attachment add_functions_to_strings.patch-2 [ 14316 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* Patch clj-1449-more-v1.patch is a good start, but needs the following additional work:

1) Update function names per the description here.
2) Per the instructions at the top of the clojure.string ns, functions should take the broader CharSequence interface instead of String. Similar to existing clojure.string functions, you will need to provide a CharSequence implementation while also calling into the String functions when you actually have a String.
3) Consider return type hints - I'm not sure they're necessary here, but I would examine the bytecode in typical calling situations to see if it would be helpful.
4) The new functions need new tests.
5) Check performance implications of the new versions vs the old with a good tool (like criterium). It would be good to know what the difference in perf actually is - some hit is worth it for a portable target.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-2
Nola Stowe made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-2
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time ||Function ||Java Interop||Patch 2 ||Patch 3|| | index-of s s | 9.539447 | 21.469917 | 20.527423 | | index-of s s from | 9.597749 | 31.037132 | 19.271089 | | index-of s char | 6.908051 | 21.945326 | 15.253318 | | index-of s char from | 7.758214 | 32.989504 | 14.615858 | | startsWith | 4.839338 | 12.833368 | 12.882044 | | endsWith | 5.790267 | 11.904179 | 12.034399 | | includes | 19.857193 | 32.479961 | 25.652444 | actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
Nola Stowe made changes -
Attachment add_functions_to_strings.patch-3 [ 14326 ]
Andy Fingerhut made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time ||Function ||Java Interop||Patch 2 ||Patch 3|| | index-of s s | 9.539447 | 21.469917 | 20.527423 | | index-of s s from | 9.597749 | 31.037132 | 19.271089 | | index-of s char | 6.908051 | 21.945326 | 15.253318 | | index-of s char from | 7.758214 | 32.989504 | 14.615858 | | startsWith | 4.839338 | 12.833368 | 12.882044 | | endsWith | 5.790267 | 11.904179 | 12.034399 | | includes | 19.857193 | 32.479961 | 25.652444 | actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

Actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
Nola Stowe made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

Actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
Nola Stowe made changes -
Attachment add_functions_to_strings.patch-3 [ 14326 ]
Nola Stowe made changes -
Attachment add_functions_to_strings.patch-2 [ 14316 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-2.patch [ 14328 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-3.patch [ 14329 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings.patch-3

Performance: Tested the following with criterium for execution mean time

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

||Function ||Java Interop||Patch 2 ||Patch 3||
| index-of s s | 9.539447 | 21.469917 | 20.527423 |
| index-of s s from | 9.597749 | 31.037132 | 19.271089 |
| index-of s char | 6.908051 | 21.945326 | 15.253318 |
| index-of s char from | 7.758214 | 32.989504 | 14.615858 |
| startsWith | 4.839338 | 12.833368 | 12.882044 |
| endsWith | 5.790267 | 11.904179 | 12.034399 |
| includes | 19.857193 | 32.479961 | 25.652444 |

actual output for each test here: https://www.evernote.com/l/ABLYZbDr8ElIs6fkODAd3poBfIm_Bfr5kLo
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 |
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 |
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) || Clojure time / Java time ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 | 1.13 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 | 1.03 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 | 1.16 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 | 1.20 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 | 1.11 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 | 1.15 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 | 1.15 |
Alex Miller made changes -
Attachment add_functions_to_strings-3.patch [ 14330 ]
Alex Miller made changes -
Attachment add_functions_to_strings-3.patch [ 14330 ]
Alex Miller made changes -
Attachment add_functions_to_strings-4.patch [ 14331 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-3.patch

Performance: Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) || Clojure time / Java time ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 | 1.13 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 | 1.03 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 | 1.16 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 | 1.20 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 | 1.11 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 | 1.15 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 | 1.15 |
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-4.patch

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) || Clojure time / Java time ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 | 1.13 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 | 1.03 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 | 1.16 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 | 1.20 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 | 1.11 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 | 1.15 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 | 1.15 |

*Screened by:* Alex Miller
Labels string ft string
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Fix Version/s Release 1.8 [ 10254 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Stuart Halloway made changes -
Approval Screened [ 10004 ] Incomplete [ 10006 ]
Priority Critical [ 2 ] Major [ 3 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-5.patch [ 14902 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-5.patch [ 14902 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-5.patch [ 14903 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:* add_functions_to_strings-4.patch

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-3 patch) || Clojure time / Java time ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.00 | 1.13 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.25 | 1.03 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" (int \n)) | 5.24 | 6.12 | 1.16 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" (int \n) 1) | 4.94 | 5.96 | 1.20 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.24 | 1.11 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.36 | 1.15 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 12.27 | 1.15 |

*Screened by:* Alex Miller
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-5.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-5 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.03 | 13.50 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.61 | 11.18 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.24 | 6.20 | 8.43 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 4.94 | 6.19 | 8.38 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.71 | 5.34 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.68 | 4.80 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 11.99 | 11.83 |

*Screened by:* Alex Miller
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-5.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-5 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 7.95 | 9.03 | 13.50 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 6.99 | 7.61 | 11.18 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.24 | 6.20 | 8.43 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 4.94 | 6.19 | 8.38 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.69 | 5.71 | 5.34 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.66 | 5.68 | 4.80 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.65 | 11.99 | 11.83 |

*Screened by:* Alex Miller
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-5.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-5 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 13.50 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 11.18 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 8.43 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 8.38 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.34 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 4.80 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 11.83 |

*Screened by:* Alex Miller
Nola Stowe made changes -
Attachment add_functions_to_strings-5.patch [ 14903 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-5.patch [ 14904 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-5.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-5 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 13.50 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 11.18 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 8.43 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 8.38 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.34 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 4.80 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 11.83 |

*Screened by:* Alex Miller
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*
Attachment add_functions_to_strings-6.patch [ 14905 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.

The major benefit of using -1
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.

The major benefit of using -1
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Stuart Halloway made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:*

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1.

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Rich Hickey made changes -
Approval Screened [ 10004 ] Incomplete [ 10006 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Screened [ 10004 ]
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1.

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Rich Hickey made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-4.patch - uses -1 to indicate not-found in index-of
* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Rich Hickey made changes -
Approval Screened [ 10004 ] Incomplete [ 10006 ]
Nola Stowe made changes -
Attachment add_functions_to_strings-7.patch [ 14998 ]
Alex Miller made changes -
Patch Code [ 10001 ] Code and Test [ 10002 ]
Approval Incomplete [ 10006 ] Screened [ 10004 ]
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-6.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* clj-1449-7.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Alex Miller made changes -
Attachment clj-1449-7.patch [ 14999 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* clj-1449-7.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-7.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Alex Miller made changes -
Attachment clj-1449-7.patch [ 14999 ]
Alex Miller made changes -
Description It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* add_functions_to_strings-7.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
It would be useful if a few common functions from Java's String were available as Clojure functions for the purposes of increasing portability to other Clojure platforms like ClojureScript.

The functions below also cover the vast majority of cases where Clojure users currently drop into Java interop for String calls - this tends to be an issue for discoverability and learning. While the goal of this ticket is increased portability, improving that is a nice secondary benefit.

|| Proposed clojure.string fn || java.lang.String method ||
| index-of | indexOf |
| last-index-of | lastIndexOf |
| starts-with? | startsWith |
| ends-with? | endsWith |
| includes? | contains |

*Patch:*

* clj-1449-7.patch - uses nil to indicate not-found in index-of

*Performance:* Tested the following with criterium for execution mean time (all times in ns).

|| Java || Clojure || Java || Clojure (-4 patch) || Clojure (-6 patch) ||
| (.indexOf "banana" "n") | (clojure.string/index-of "banana" "n") | 8.70 | 9.03 | 9.27 |
| (.indexOf "banana" "n" 1) | (clojure.string/index-of "banana" "n" 1) | 7.29 | 7.61 | 7.66 |
| (.indexOf "banana" (int \n)) | (clojure.string/index-of "banana" \n) | 5.34 | 6.20 | 6.20 |
| (.indexOf "banana" (int \n) 1) | (clojure.string/index-of "banana" \n 1) | 5.38 | 6.19 | 6.24 |
| (.startsWith "apple" "a") | (clojure.string/starts-with? "apple" "a") | 4.84 | 5.71 | 5.65 |
| (.endsWith "apple" "e") | (clojure.string/ends-with? "apple" "e") | 4.82 | 5.68 | 5.70 |
| (.contains "baked apple pie" "apple") | (clojure.string/includes? "baked apple pie" "apple") | 10.78 | 11.99 | 12.17 |

*Screened by:* Stu, who prefers nil over -1 - add_functions_to_strings-6.patch

*Note:* In both Java and JavaScript, indexOf will return -1 to indicate not-found, so this is (at least in these two cases) the status quo. The benefit of nil return in Clojure is that it can be used as a found/not-found condition. The benefit of a -1 return is that it matches Java/JavaScript and that the return type can be hinted as a primitive long, allowing you to feed it into some other arithmetic or string operation without boxing.
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (29)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: