Public Vars

Back

doto (clj)

(source)

macro

(doto x & forms)
Evaluates x then calls all of the methods and functions with the value of x supplied at the front of the given arguments. The forms are evaluated in order. Returns x. (doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2))

Examples

hraberg/deuce
(ns deuce.emacs.alloc
  (:use [deuce.emacs-lisp :only (defun defvar) :as el]
        [taoensso.timbre :as timbre
         :only (trace debug info warn error fatal spy)])
  (:require [clojure.core :as c]
            [clojure.walk :as w]
            [deuce.emacs-lisp.cons :as cons])
  (:refer-clojure :exclude [vector cons list])
  (:import [java.util Arrays]
           [java.lang.management ManagementFactory MemoryNotificationInfo MemoryType MemoryPoolMXBean]
           [javax.management NotificationListener NotificationEmitter Notification]))

(defun make-vector (length init)
  "Return a newly created vector of length LENGTH, with each element being INIT.
  See also the function `vector'."
  (doto (object-array length)
    (Arrays/fill init)))
lynaghk/zmq-async
(ns com.keminglabs.zmq-async.t-core
  (:require [com.keminglabs.zmq-async.core :refer :all]
            [clojure.core.async :refer [go close! >!! <!! chan timeout alts!!]]
            [midje.sweet :refer :all])
  (:import org.zeromq.ZMQ))

(let [context (create-context)]
  (fact "Poller selects correct socket"
    (with-open [sock-A (doto (.createSocket (context :zcontext) ZMQ/PULL)
                         (.bind "inproc://A"))
                sock-B (doto (.createSocket (context :zcontext) ZMQ/PULL)
                         (.bind "inproc://B"))]

      (doto (.createSocket (context :zcontext) ZMQ/PUSH)
        (.connect "inproc://A")
        (.send "A message"))

(fact "ZMQ looper"
  (with-state-changes [(around :facts
                               (let [{:keys [zmq-thread addr sock-server sock-client async-control-chan queue]
                                      :as context} (create-context)
                                      _      (do
                                               (.bind sock-server addr)
                                               (.start zmq-thread))
                                      zcontrol (doto sock-client
                                                 (.connect addr))]

    ;;TODO: rearchitect so that one concern can be tested at a time?
    ;;Then the zmq looper would need to use accessible mutable state instead of loop/recur...
    (fact "Opens sockets, conveys messages between sockets and async control channel"
      (let [test-addr "inproc://open-test"
            test-id "open-test"
            test-sock (doto (.createSocket (context :zcontext) ZMQ/PAIR)
                        (.bind test-addr))]

(fact "core.async looper"
  (with-state-changes [(around :facts
                               (let [context (create-context)
                                     {:keys [zmq-thread addr sock-server sock-client async-control-chan async-thread queue]} context
                                     acontrol async-control-chan
                                     zcontrol (doto sock-server
                                                (.bind addr))]


(fact "Integration"
  (with-state-changes [(around :facts
                               (let [context (doto (create-context)
                                               (initialize!))
                                     {:keys [async-thread zmq-thread]} context]

        (.send (doto (.createSocket (context :zcontext) ZMQ/PAIR)
                 (.connect addr))
               test-msg)
        (String. (<!! out)) => test-msg))

        (.send (doto (.createSocket (context :zcontext) ZMQ/PAIR)
                 (.connect addr))
               test-msg)
        (String. (<!! out)) => test-msg))

        (let [raw (doto (.createSocket (context :zcontext) ZMQ/PAIR)
                    (.connect addr))]
          (>!! in test-msg)
aaronc/fx-clj
(ns ^:no-doc fx-clj.core.convert
  (:require
    [fx-clj.core.extensibility :refer [convert-arg]]
    [fx-clj.util :as util]
    [clojure.core.async :refer [put!]]
    ;;[camel-snake-kebab.core :as csk]
    [org.tobereplaced.lettercase :as lettercase])
  (:import (javafx.event EventHandler)
           (clojure.core.async.impl.channels ManyToManyChannel)
           (javafx.util Callback)
           (javafx.collections ObservableList FXCollections)
           (javafx.scene Node)
           (javax.swing JComponent)
           (javafx.embed.swing SwingNode)
           (javafx.beans.property Property)
           (fx_clj.binding ReactiveAtomObservable)
           [freactive IReactiveAtom]))

(defmethod convert-arg [Node JComponent] [nt jc _]
  (doto (SwingNode.)
    (.setContent jc)))
Netflix/mantis-mql
   Finally MQL also provides an 'any' search for handling unknown property
   locations:
   `select * from stream where e['falcor.paths'][*]['path'] == 'search'`"
  (:require [clojure.test :refer :all]
            [io.mantisrx.mql.jvm.core :as mql]
            [io.mantisrx.mql.transformers :as t]
            [rx.lang.clojure.core :as rx]
            [rx.lang.clojure.blocking :as rxb]
            [io.mantisrx.mql.properties :as mqlp])
  (:import rx.Observable java.util.concurrent.TimeUnit))

(deftest test-mql-get-in-works-on-java-maps
  (testing "mqlp/get-in works with Java maps."
    (let
      [m1 (doto (java.util.HashMap.)
            (.put "test" "bacon")
            identity)]
      (is (= "bacon" (mqlp/get-in m1 ["test"])))))
  (testing "mqlp/get-in works with nested Java maps."
    (let
      [m1 (doto (java.util.HashMap.)
            (.put "test" "bacon")
            identity)
       m2 (doto (java.util.HashMap.)
            (.put "test" m1)
            identity)]
      (is (= "bacon" (mqlp/get-in m2 ["test" "test"]))))))

(deftest test-mql-get-in-works-with-mixed-java-maps-and-lists
  (testing "mqlp/get-in works with mixed Java maps and lists."
    (let
      [list1 (java.util.ArrayList. [120.0 55.2 111])
       map1 (doto (java.util.HashMap.)
            (.put "latencies" list1)
            identity)
       list2 (java.util.ArrayList. [map1])
       m2 (doto (java.util.HashMap.)
            (.put "metrics" list2)
            identity)]
      (is (= (mqlp/get-in m2 ["metrics" 0 "latencies" 2]))))))
JohnnyJayJay/poker
(ns poker.discord.state
  (:require [mount.core :refer [defstate]]
            [clojure.edn :as edn]
            [clojure.core.async :as async]
            [discljord.messaging :as dr]
            [discljord.connections :as dg]
            [datalevin.core :as datalevin])
  (:import (java.util.concurrent Executors ExecutorService)))

(defstate db-conn
  :start (doto (datalevin/open-kv "data") (datalevin/open-dbi "language"))
  :stop (datalevin/close-kv db-conn))