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.

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.

Activity

People

Vote (25)
Watch (4)

Dates

  • Created:
    Updated: