https://github.com/beoliver/insert-randomly
https://github.com/beoliver/insert-randomly
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/beoliver/insert-randomly
- Owner: beoliver
- License: epl-1.0
- Created: 2018-07-22T09:20:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-22T09:35:07.000Z (over 7 years ago)
- Last Synced: 2025-01-29T06:49:08.939Z (12 months ago)
- Language: Clojure
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# insert-randomly
When you you want to spice up your data
[](https://clojars.org/beoliver/insert-randomly)
## Usage
```clojure
(require '[insert-randomly.core :as r])
```
### `insert-randomly`
```clojure
core> (r/insert-randomly [1 2 3 4 5] :woops)
[1 2 3 :woops 4 5]
core> (r/insert-randomly [1 2 3 4 5] 3 :woops)
[1 2 :woops 3 4 :woops :woops 5]
```
### `insert-result-randomly`
```clojure
core> (r/insert-result-randomly [1 2 3 4 5] gensym)
[G__17452 1 2 3 4 5 G__17453 G__17454]
core> (r/insert-randomly [1 2 3 4 5] 3 (constantly :woops))
[1 2 :woops :woops 3 4 5 :woops]
```
### `replace-randomly`
```clojure
core> (r/replace-randomly [1 2 3 4 5] :ok)
[1 :ok 3 4 5]
core> (r/replace-randomly [1 2 3 4 5] 20 :ok)
[:ok :ok :ok :ok :ok]
;; also works with maps
core> (r/replace-randomly {:a 1 :b 2 :c 3} 2 :surprise)
{:a 1, :b :surprise, :c :surprise}
```
### `update-randomly`
```clojure
core> (require '[clojure.string :as str])
nil
core> (r/update-randomly ["the" "quick" "brown" "fox"] 2 str/reverse)
["the" "kciuq" "brown" "xof"]
;; again - we can use it with maps
core> (r/update-randomly {:the "the" :quick "quick" :brown "brown" :fox "fox"} 2 str/reverse)
{:the "the", :quick "quick", :brown "nworb", :fox "xof"}
;; if you pass a list it will be converted into a vector
;; this is so we can use `update` internally
core> (r/update-randomly (list 1 2 3 4 5) (constantly :foo))
[1 2 3 :foo 5]
```