All Projects → vvvvalvalval → Supdate

vvvvalvalval / Supdate

Licence: mit
Clojure's update with superpowers.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Supdate

Algorithms Data Structures In Typescript
Stars: ✭ 175 (-7.89%)
Mutual labels:  data-structures
Fun
操作系统,数据结构,网络,python,go,web
Stars: ✭ 181 (-4.74%)
Mutual labels:  data-structures
Leetcode Algorithm
分类整理leetcode算法题解,代码语言采用c++与python实现
Stars: ✭ 184 (-3.16%)
Mutual labels:  data-structures
Crdt
A Golang implementation of CRDTs.
Stars: ✭ 176 (-7.37%)
Mutual labels:  data-structures
Immutable
Thread-safe, persistent, immutable collections for the Crystal language
Stars: ✭ 179 (-5.79%)
Mutual labels:  data-structures
Library Checker Problems
The problem data (Test case generator, judge's solution, task, ...) of Library Checker
Stars: ✭ 183 (-3.68%)
Mutual labels:  data-structures
Extcore
An extended core library for F#.
Stars: ✭ 172 (-9.47%)
Mutual labels:  data-structures
Rust Algorithm Club
Learn algorithms and data structures with Rust
Stars: ✭ 184 (-3.16%)
Mutual labels:  data-structures
Emuto
manipulate JSON files
Stars: ✭ 180 (-5.26%)
Mutual labels:  data-structures
Interview Questions
List of all the Interview questions practiced from online resources and books
Stars: ✭ 187 (-1.58%)
Mutual labels:  data-structures
Atomix
A reactive Java framework for building fault-tolerant distributed systems
Stars: ✭ 2,182 (+1048.42%)
Mutual labels:  data-structures
Leetcode
LeetCode solutions, written in python and cpp(LeetCode解题报告,记录自己的leetcode成长之路)
Stars: ✭ 179 (-5.79%)
Mutual labels:  data-structures
Cs61b sp19
Data Structures
Stars: ✭ 185 (-2.63%)
Mutual labels:  data-structures
Data Structures And Algorithms In Cpp
This repository is in development phase and will soon provide you with c++ code of various data structures and algorithms
Stars: ✭ 176 (-7.37%)
Mutual labels:  data-structures
Dailycodebase
2 month data structures and algorithmic scripting challenge starting from 20th December 2018 - Coding is Fun! 💯💯 Do it everyday!! Also, Do give us a ⭐ if you liked the repository
Stars: ✭ 186 (-2.11%)
Mutual labels:  data-structures
Algo
Algorithms and data structures implemented in Go, JS, TypeScript, Rust, and Swift.
Stars: ✭ 174 (-8.42%)
Mutual labels:  data-structures
Algorithms4 Common
🔥Algorithms, 4th Edition 算法4精华笔记,通俗理解,算法收集与强化。
Stars: ✭ 183 (-3.68%)
Mutual labels:  data-structures
Coursera
Source Code and Starter Code for Accelerated Computer Science Fundamentals Specialization on Coursera
Stars: ✭ 189 (-0.53%)
Mutual labels:  data-structures
Programmers Community
This repository contains various solution of a problem in Ruby, C, C++, Python and Java.
Stars: ✭ 189 (-0.53%)
Mutual labels:  data-structures
Data Structures And Algorithms Hacktoberfest18
List of data structures and algorithms. Feel free to contribute under Hacktoberfest '18!
Stars: ✭ 187 (-1.58%)
Mutual labels:  data-structures

supdate

Clojure's update with superpowers.

Clojars Project

This library provides a supdate macro which lets you transform Clojure data structures declaratively, using a data-driven specification which structure matches the schema of the input.

The benefit is that such specifications eliminate a lot of the boilerplate code involved when transforming nested data structures.

In addition, supdate is a macro that leverages static information on a best-effort basis in order to make the performance comparable to hand-written code. Dynamic pre-compilation (via compile) is also available to achieve better performance while remaining fully dynamic.

Usage

(require '[vvvvalvalval.supdate.api :as supd :refer [supdate]])

;; canonical example
(def my-input
  {:a 1
   :b [1 2 3]
   :c {"d" [{:e 1 :f 1} {:e 2 :f 2}]}
   :g 0
   :h 0
   :i 0})

(supdate
  my-input
  {:a inc
   :b [inc]
   :c {"d" [{:e inc}]}
   :g [inc inc inc]
   :my-missing-key inc
   :i false
   })
=> {:a 2,
    :b [2 3 4],
    :c {"d" [{:e 2, :f 1} {:e 3, :f 2}]}
    :g 3,
    :h 0}

See also the tests for more examples.

Emulating standard library operations

supdate generalizes several functions of Clojure's standard library:


;;;; Emulating clojure.core/update
(update {:a 1 :b 1} :a inc)
=> {:a 2 :b 1}
(supdate {:a 1 :b 1} {:a inc})
=> {:a 2 :b 1}

;;;; Emulating clojure.core/update-in
(update-in {:a {"b" [{:c 1}]}}
  [:a "b" 0 :c] inc)
=> {:a {"b" [{:c 2}]}}
(supdate {:a {"b" [{:c 1}]}}
  {:a {"b" {0 {:c inc}}}})
=> {:a {"b" [{:c 2}]}}
;; NOTE: unlike update-in, if a key is missing in the input, 
;; the transformation will be skipped instead of creating new maps.

;;;; Emulating clojure.core/map 
(map dec (range 10))
=> (-1 0 1 2 3 4 5 6 7 8)
(supdate (range 10) [dec])
=> (-1 0 1 2 3 4 5 6 7 8)
;; Note: unlike map, if the input is a vector, the output will also be a vector.

;;;; Emulating dissoc
(dissoc {:a 1 :b 2 :c 3}
  :a :b :d)
=> {:c 3}
(supdate {:a 1 :b 2 :c 3}
  {:a false :b false})
=> {:c 3}

Pre-compiling transforms

A compile function is available to make execution faster:


(def transform
  (supd/compile {:a inc
                 :b [inc]
                 :c {"d" [{:e inc}]}
                 :g [inc inc inc]
                 :missing-key inc
                 :i false
                 }))

(transform {:a 1
            :b [1 2 3]
            :c {"d" [{:e 1 :f 1} {:e 2 :f 2}]}
            :g 0
            :h 0
            :i 0})
=> {:a 2,
    :b [2 3 4],
    :c {"d" [{:e 2, :f 1} {:e 3, :f 2}]}
    :g 3,
    :h 0}

Comparison to Specter

This library is in the same space as Specter, but we don't see it as a replacement to Specter. We believe this library is useful in situations where using Specter is overkill.

More specifically:

  • Specter's transform is useful for making one sophisticated transformation, whereas supdate is good at making many basic transformations at once.
  • Specter provides a select operation, supdate is only about transformation.
  • Arguably, supdate is easier to learn.
  • Specter is extensible, supdate is not.

License

Copyright © 2016 Valentin Waeselynck and contributors

Distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].