Giter Site home page Giter Site logo

clj-contrib's Introduction

clj-contrib

Build Status Clojars Project Clojure version

A library of functions to enhance clojure.core.

Getting Started

Using the clj-contrib library.

Installation

See Clojars for adding this library to various project types (lein, boot, deps.edn, etc).

Include the Library

In the REPL

(require '[clj-contrib.core :as cc])
(require '[clj-contrib.core.async :as cca])

In your application

(ns my-app.core
  (:require [clj-contrib.core :as cc])
  (:require [clj-contrib.core.async :as cca]))

Use the Library

A few usage examples.

clj-contrib.core

;;; Simple Values
;; Numbers

; Check if two numbers are within a threshold.
(same-ish? 1.001 1.003 0.005)

;; Booleans
; Get the boolean value of the argument.
(bool "true")

;;; Operations
;; Flow Control

; as->, with the nil checking of some->.
(as-some-> {:one 1, :two 2} mythings
             (:one mythings)
             (inc mythings)
             (str "These " mythings " things and more!"))

;;; Collections
;; Maps

; count the errors in a collection.
(errors [{:error "foo"}, {:success "foo"}])
(errors {:success "foo"})

; count the success (non-errors) in a collection.
(success [{:success "foo"}, {:success "foo"}])
(success {:error "foo"})

clj-contrib.core.async

;;; loop-until: Take from an async channel and execute a function against the value.
;;;             Stop if the function returns falsey or the max is exceeded.
;; Stops early when the :error is encountered.
(let [ch (async/chan)
      stop-on-error (fn [result] (println result) (not (contains? result :error)))]
  (async/put! ch {:success "some data"})
  (async/put! ch {:error "bad data"})
  (async/put! ch {:success "more data"})
  (async/put! ch {:success "data trifecta"})
  (loop-until ch stop-on-error 3))

;; Executes to the max of 3.
(let [ch (async/chan)
      stop-on-error (fn [result] (println result) (not (contains? result :error)))]
  (async/put! ch {:success "some data"})
  (async/put! ch {:success "more data"})
  (async/put! ch {:success "data trifecta"})
  (async/put! ch {:error "bad data"})
  (loop-until ch stop-on-error 3))

clj-contrib's People

Contributors

wdhowe avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.