GithubHelp home page GithubHelp logo

strojure / vectops Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 46 KB

Basic operations with Clojure vectors.

License: The Unlicense

Clojure 100.00%
persistent-data-structure vectors optimization clojure clojurescript

vectops's Introduction

vectops

Basic operations with Clojure(Script) vectors.

Clojars Project

cljdoc badge cljs compatible tests

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.

(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.

(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.

(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

vectops's People

Contributors

serioga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vectops's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.