• Stars
    star
    41
  • Rank 646,130 (Top 14 %)
  • Language
    Clojure
  • License
    Other
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility library for Clojure and ClojureScript

kezban Build Status GitHub License

Utility library for Clojure and ClojureScript.

The library targets Clojure 1.8 and above.

Leiningen

Clojars Project

Usage

kezban.core

;;use kezban.core
(use 'kezban.core)

when-let*

user=> (when-let* [a 1 b 2 c 3]
                  (println "I <3 Clojure")
                  a)
=> "I <3 Clojure"
=> 1

;;returns nil when one binding is nil or false
user=> (when-let* [a 1 b nil c 3]
                  (println "Please print me!")
                  a)
=> nil                              

if-let*

user=> (if-let* [a 1 b 2 c (+ a b)]
                c)
=> 3

;;returns then part when one binding is nil or false
user=> (if-let* [a 1 b nil c 3]
                "Nope not here"
                "Here I Am!")
=> "Here I Am!"         

cond-as->

(cond-as-> 1 n
           true (+ n 1)
           false (+ n 2)
           true  (+  5 n))
=> 7

->>>

;; Alternative to ->, ->> and (comp) with one arg
;; Applying Left-To-Right
;; First Argument has to be a value(input)!

;; comp equivalent: ((comp #(+ 1 %) #(+ % 1) inc) 5)
;; standard equivalent (+ 1 (+ (inc 5) 1))

user=> (->>> 5 inc #(+ % 1) #(+ 1 %)) ;;5 is the input
=> 8


;; comp equivalent: ((comp inc second reverse) '("a" 2 8 "b"))
;; standard equivalent (inc (second (reverse '("a" 2 8 "b"))))

user=> (->>> '("a" 2 8 "b") reverse second inc) ;;'("a" 2 8 "b") is the input
=> 9

nth-safe

(def coll [1 2 3 4 5])

user=> (nth-safe coll 0)
=> 1

user=> (nth-safe coll 12)
=> nil

user=> (nth-safe coll 12 "not-found-value")
=> "not-found-value"

nnth

(nnth [1 [2 3 [4 5]]] 1 2 1)
=> 5

def-

(def- my-coll [1 2 3])
=> #'kezban.core/my-coll

(:private (meta #'kezban.core/my-coll))
=> true

xor

(xor false true nil)
=> true

(xor false nil)
=> nil

pprint-macro

(pprint-macro (when-let [a 1]
                (println a)))
(let*
 [temp__4657__auto__ 1]
 (if temp__4657__auto__ (do (let* [a temp__4657__auto__] (println a)))))
=> nil

quoted?

(quoted? '(+ 1  2))
=> true

(quoted? (+ 1  2))
=> false

array?

(array? (int-array 1))
=> true

(array? :int (int-array 1))
=> true

lazy?

(lazy? (map inc [1 2 3]))
=> true

any-pred

(filter (any-pred even? odd?) [2 4 5 7])
=> (2 4 5 7)

try-> and try->>

(try-> 5 inc dec str inc) ;;also thread last version: try->>
=> nil

multi-comp

(def data [{:v 12, :a 10} {:v 21, :a 113} {:v 1, :a 2} {:v 12, :a 223} {:v 100, :a 23} {:v 1, :a 113}])

(sort #(multi-comp [:a :v] > %1 %2) data)
;or
(sort #(multi-comp [:a :v] %2 %1) data)
=> ({:v 12, :a 223} {:v 21, :a 113} {:v 1, :a 113} {:v 100, :a 23} {:v 12, :a 10} {:v 1, :a 2})

with-out

(with-out 
 (println "Normal out") 
 (.println (System/err) "Error occurred!"))
=> {:err "Error occurred!\n", :out "Normal out\n"}

letm

(letm [a 1
       b (+ a 1)])
=> {:a 1, :b 2}

in?

(in? 3 [1 2 3 4])
=> true

take-while-and-n-more

(take-while-and-n-more even? 2 [2 4 6 7 9 13 15])
=> (2 4 6 7 9)

dissoc-in

(dissoc-in {:a {:b {:c 1 :d 2}}} [:a :b :d])
=> {:a {:b {:c 1}}}

with-timeout

(with-timeout 100
              (Thread/sleep 1500))
=> CompilerException java.util.concurrent.TimeoutException

(with-timeout 1000
              (Thread/sleep 500)
              5)
=> 5

url->file

(url->file "http://file.url" (io/file "your file path to get content"))
=> returns your file instance

cond-let

(cond-let [a 5
           b (+ a 1)]

          (even? a)
          (println "a is odd")

          (even? b)
          (println "b is even"))
b is even
=> nil

keywordize

(keywordize "hey Whats Up?")
=> :hey-whats-up?

source-clj-file

(source-clj-file 'clojure.string)
=> returns clojure.string's namespace source code in string

time*

;;unlike time, time* allows you to provide more than one form
(time* 
  (Thread/sleep 2500)
  12)
  
=> {:duration 2505.328818, :result 12}

process-lazy-seq

(process-lazy-seq (fn [i]
                    (println (inc i))) 10000 (range))
                    
;; we can process 10000 data at time and not getting OutOfMemory Exception

when-no-aot

;; binding will happen when *compile-files* set to false
(def db-conn (when-no-aot (create-db-connection!)))

defay

(defay current-time  (println "Hi!") (System/currentTimeMillis))
;; Hi!
;;=> 1587327846466

@current-time

;;=> 1587327846466

;; Expands to this:
(def current-time (delay (println "Hi!")
                         (System/currentTimeMillis)))

(when-not *compile-files* @current-time)

locals

(defn my-fn
  [a]
  (let [b 2]
    (locals)))

(my-fn 1)
;;=> {a 1, b 2}

prog1

(prog1 (+ 1 2)
  (println "Result: " <>))

;;Result:  3
;;=> 3

defm

(defm my-add [x y]
  (println "Result: " (+ x y))
  (+ x y))

(my-add 1 2)
;;Result:  3
;;=> 3

(my-add 1 2)
;;=> 3
Memoized function, expands to this:

(def my-add
  (memoize
    (fn [x y]
      (println "Result: " (+ x y))
      (+ x y))))

License

  Copyright © 2022 Ertuğrul Çetin
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

More Repositories

1

racing-game-cljs

A 3D racing game built with ClojureScript, React and ThreeJS
Clojure
234
star
2

ClojureNews

Clojure News Web Application - (Hacker News Clone)
Clojure
220
star
3

GlueList

GlueList is brand new list implementation which is faster than classic List implementations
Java
163
star
4

re-frame-flow

Graph based visualization tool for re-frame event chains
Clojure
145
star
5

jme-clj

A Clojure 3D Game Engine (Wrapper), Powered by jMonkeyEngine
Clojure
131
star
6

herfi

3D multiplayer game prototype written in Clojure and ClojureScript
Clojure
106
star
7

code3dworld

Learn programming in 3D World
Clojure
70
star
8

enion

Enion Online is an Epic PvP Battle game between Orcs and Humans. The game is written using Clojure and ClojureScript, and utilizes the PlayCanvas game engine.
Clojure
63
star
9

CommentRemover

Source Code Comment Remover For Java
Java
59
star
10

konva-cljs

A minimalistic ClojureScript interface to react-konva
Clojure
23
star
11

playcanvas-cljs-demo

PlayCanvas ClojureScript Demo App
JavaScript
20
star
12

overload-fn

Function overloading on type for Clojure
Clojure
19
star
13

lein-nsort

Leiningen plugin that checks that order of namespace declarations for Clojure and ClojureScript
Clojure
17
star
14

procedure.async

Async procedures for Clojure
Clojure
13
star
15

patika

Clojure routing library which is an abstraction over Liberator + Compojure
Clojure
13
star
16

finite-cache

finite-cache is a Clojure caching library that allows you to limit the size of a cache object.
Clojure
12
star
17

asynctor

Minimal core.async inspector library for Clojure and ClojureScript
Clojure
10
star
18

babylon-cljs

3D character controller prototype project. It showcases how to integrate BabylonJS with ClojureScript.
Clojure
9
star
19

datomic-backupper

Datomic Backupper
Clojure
4
star
20

segmentum

Segmentum is an unified customer data platform. Open source alternative of Segment.com
Clojure
3
star
21

spark-definitive-guide-examples

Spark: The Definitive Guide's Code in Clojure
Clojure
3
star
22

the-repl

Clojure REPL built with Java Swing GUI
Clojure
2
star
23

parse_struct

Parse C struct dumps in clojure
Clojure
1
star
24

random-clojure-fn

Chrome extension that generates random clojuredocs.org URLs to learn Clojure's standard library.
JavaScript
1
star