Back

replace-first (clj)

(source)

function

(replace-first s match replacement)
Replaces first instance of match with replacement in s.

Examples

PacktWorkshops/The-Clojure-Workshop
(ns hello-test.core-test
  (:require [cljs.test :refer-macros [are async deftest is testing]]
            [clojure.test.check.generators :as gen]
            [clojure.test.check.properties :refer-macros [for-all]]
            [clojure.test.check.clojure-test :refer-macros [defspec]]
            [cuerdas.core :as str]
            [hello-test.core :refer [profanity-filter http-get prefix-digit-remover]]))

(defspec prefix-digit-remover-test 1000
         (for-all [some-string gen/string-ascii]
                  (=
                    ;(str/replace-first some-string "1" "a") ;;; will result in failing test. An example of failing test
                    (if (str/starts-with? some-string "1") (str/replace-first some-string "1" "a") some-string)
                    (prefix-digit-remover some-string))))