Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strojure/vectops
Basic operations with Clojure vectors.
https://github.com/strojure/vectops
clojure clojurescript optimization persistent-data-structure vectors
Last synced: 2 months ago
JSON representation
Basic operations with Clojure vectors.
- Host: GitHub
- URL: https://github.com/strojure/vectops
- Owner: strojure
- License: unlicense
- Created: 2022-09-01T08:41:45.000Z (over 2 years ago)
- Default Branch: default
- Last Pushed: 2023-03-09T10:39:05.000Z (almost 2 years ago)
- Last Synced: 2024-11-29T03:05:49.433Z (3 months ago)
- Topics: clojure, clojurescript, optimization, persistent-data-structure, vectors
- Language: Clojure
- Homepage:
- Size: 44.9 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vectops
Basic operations with Clojure(Script) vectors.
[![Clojars Project](https://img.shields.io/clojars/v/com.github.strojure/vectops.svg)](https://clojars.org/com.github.strojure/vectops)
[![cljdoc badge](https://cljdoc.org/badge/com.github.strojure/vectops)](https://cljdoc.org/d/com.github.strojure/vectops)
[![cljs compatible](https://img.shields.io/badge/cljs-compatible-green)](https://clojurescript.org/)
[![tests](https://github.com/strojure/vectops/actions/workflows/tests.yml/badge.svg)](https://github.com/strojure/vectops/actions/workflows/tests.yml)## Purpose
* Provide functions for basic operations with persistent vectors like inserting
or removing elements at index.
* Performant implementation without extra dependencies.
* Support Clojure and ClojureScript.## Usage
### insert-at
The function `insert-at` inserts element in persistent vector at specified
index. There is also `insert-at!` function for transient vectors.```clojure
(ns readme.usage.insert-at
(:require [strojure.vectops.core :as vec]))(vec/insert-at [0 1 2 3 4] 0 :x)
#_=> [:x 0 1 2 3 4](vec/insert-at [0 1 2 3 4] 2 :x)
#_=> [0 1 :x 2 3 4](vec/insert-at [0 1 2 3 4] 5 :x)
#_=> [0 1 2 3 4 :x](vec/insert-at [0 1 2 3 4] 6 :x)
;; Execution error (IndexOutOfBoundsException)(vec/insert-at nil 0 :x)
#_=> [:x]
```### remove-at
The function `remove-at` removes element at specified index from persistent
vector. There is also `remove-at!` function for transient vectors.```clojure
(ns readme.usage.remove-at
(:require [strojure.vectops.core :as vec]))(vec/remove-at [0 1 2 3 4] 0)
#_=> [1 2 3 4](vec/remove-at [0 1 2 3 4] 2)
#_=> [0 1 3 4](vec/remove-at [0 1 2 3 4] 4)
#_=> [0 1 2 3](vec/remove-at [0 1 2 3 4] 5)
;; Execution error (IndexOutOfBoundsException)
```### swap-at
The function `swap-at` swaps elements in persistent vector at two indexes.
There is also `swap-at!` function for transient vectors.```clojure
(ns readme.usage.swap-at
(:require [strojure.vectops.core :as vec]))(vec/swap-at [0 1 2 3 4] 1 3)
#_[0 3 2 1 4](vec/swap-at [0 1 2 3 4] 0 5)
;; Execution error (IndexOutOfBoundsException)
```## Performance
* [vec/insert-at](doc/benchmarks/insert_at.cljc)
* [vec/remove-at](doc/benchmarks/remove_at.cljc)
* [vec/swap-at](doc/benchmarks/swap_at.cljc)