Clojure

Add clojure.string functions for portability to ClojureScript

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Triaged

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)

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)

People

Vote (25)
Watch (3)

Dates

  • Created:
    Updated: