Back

join (clj)

(source)

function

(join coll) (join separator coll)
Returns a string of all elements in coll, as returned by (seq coll), separated by an optional separator.

Examples

clojure
(ns clojure.test-clojure.string
  (:require [clojure.string :as s])
  (:use clojure.test))

(deftest t-join
  (are [x coll] (= x (s/join coll))
       "" nil
       "" []
       "1" [1]
       "12" [1 2])
  (are [x sep coll] (= x (s/join sep coll))
       "1,2,3" \, [1 2 3]
       "" \, []
       "1" \, [1]
       "1 and-a 2 and-a 3" " and-a " [1 2 3]))
babashka/babashka
(require '[clojure.edn :as edn]
         '[clojure.string :as str])

(def cmd ["-P" (str "-A" (str/join aliases))])
swarmpit/swarmpit
(ns swarmpit.component.toolbar
  (:require [material.icon :as icon]
            [material.components :as comp]
            [sablono.core :refer-macros [html]]
            [clojure.string :refer [join]]
            [rum.core :as rum]))

(rum/defcs menu < rum/static
                  (rum/local nil :menu/anchor)
  [{anchor :menu/anchor} items]
  (let [items-hash (join (map :name items))
        main-action (first (filter #(= true (:main %)) items))
        rest-actions (filter #(not= true (:main %)) items)]
    (comp/box
      {}
      (comp/button-group
        {:className  "Swarmpit-form-toolbar-btn"
         :variant    "contained"
         :color      "primary"
         :aria-label "split button"}
        (comp/button
          {:startIcon (:icon main-action)
           :onClick   (:onClick main-action)}
          (:name main-action))
        (comp/button
          {:color         "primary"
           :size          "small"
           :aria-label    "select action"
           :aria-haspopup "menu"
           :onClick       #(reset! anchor (.-currentTarget %))}
          (icon/arrow-dropdown {})))
      (menu-popper items-hash rest-actions anchor))))
braidchat/braid
(ns braid.core.client.gateway.forms.join-group.events
  (:require
   [braid.core.client.gateway.helpers :as helpers :refer [get-url-group-id]]
   [braid.base.client.state :refer [reg-event-fx]] ;; TODO should use reg.base.api/register-events!
   [clojure.string :as string]
   [re-frame.core :refer [dispatch]]))

(reg-event-fx
  ::remote-join-group!
  (fn [{state :db} _]
    {:edn-xhr {:method :put
               :uri (str "/groups/" (get-url-group-id) "/join")
               :headers {"x-csrf-token" (state :csrf-token)}
               :on-complete
               (fn [response]
                 (set! js/window.location (str "/groups/" (get-url-group-id) "/inbox")))
               :on-error
               (fn [error]
                 (when-let [k (get-in error [:response :error])]
                   (dispatch [:braid.notices/display! [(keyword "join-group-error" (get-url-group-id)) k :error]])))}}))
pallet/pallet
(ns pallet.crate.etc-default
  "Generation and installation of /etc/default-style files."
  (:require
   [clojure.string :as string]
   [pallet.actions :refer [remote-file]]
   [pallet.crate :refer [defplan]]
   [pallet.script.lib :as lib]
   [pallet.stevedore :as stevedore]
   [pallet.stevedore :refer [with-source-line-comments]]
   [pallet.utils :refer [apply-map]]))

   e.g. (write \"tomcat6\"
          :JAVA_OPTS \"-Xmx1024m\"
          \"JSP_COMPILER\" \"javac\")"
  [filename & key-value-pairs]
  (let [file (if (= \/ (first filename))
               filename
               (str (with-source-line-comments false
                      (stevedore/script (~lib/etc-default)))
                    "/" filename))]
    (remote-file
     file
     :owner "root"
     :group "root"
     :mode 644
     :content (string/join
               \newline
               (for [[k v] (partition 2 key-value-pairs)]
                 (str (name k) "=" (pr-str v)))))))

   e.g. (write_opts \"tomcat6\"
          {:JAVA_OPTS \"-Xmx1024m\"
           \"JSP_COMPILER\" \"javac\"}
          {:overwrite-changes true})"
  [filename key-values options]
  (let [file (if (= \/ (first filename))
               filename
               (str (with-source-line-comments false
                      (stevedore/script (~lib/etc-default)))
                    "/" filename))]
    (apply-map
     remote-file
     file
     :owner "root"
     :group "root"
     :mode 644
     :content (string/join
               \newline
               (for [[k v] key-values]
                 (str (name k) "=" (pr-str v))))
     options)))
cljsjs/packages
(deftask generate-deps []
  (let [tmp (c/tmp-dir!)
        new-deps-file (io/file tmp "deps.cljs")
        path->foreign-lib (fn [path]
                            (let [[js-path parent ns] (re-matches #"cljsjs/three-examples/development/(.*/)?(.*)\.inc\.js" path)]
                              {:file     path
                               :file-min (str "cljsjs/three-examples/production/" parent ns ".min.inc.js")
                               :requires ["cljsjs.three"]
                               :provides [(str "cljsjs.three-examples."
                                               (when (some? parent) (clojure.string/replace parent "/" "."))
                                               ns)]}))]
    (with-pre-wrap
      fileset
      (let [existing-deps-file (->> fileset c/input-files (c/by-name ["deps.cljs"]) first)
            existing-deps      (-> existing-deps-file c/tmp-file slurp read-string)
            dev-files          (->> fileset c/input-files (c/by-re [#"^cljsjs/three-examples/development/.*\.inc\.js"]))
            libs               (map (comp path->foreign-lib c/tmp-path) dev-files)
            new-deps           (assoc-in existing-deps [:foreign-libs] libs)]
        (util/info "Generating deps.cljs.\n")
        (spit new-deps-file (pr-str new-deps))
        (-> fileset (c/add-resource tmp) c/commit!)))))

(deftask generate-externs []
  (let [tmp (c/tmp-dir!)
        externs-file (io/file tmp "cljsjs/three-examples/common/three-examples.ext.js")]
    (with-pre-wrap
      fileset
      (let [threejs-path (->> fileset
                              c/input-files
                              (c/by-re [#"build/three.js"])
                              (map (comp #(.getPath %) c/tmp-file))
                              first)
            package-file (->> fileset
                              c/input-files
                              (c/by-re [#"package.json"])
                              (map c/tmp-file)
                              first)
            input-string (->> fileset
                              c/input-files
                              (c/by-re [#"examples/js/.*\.js"])
                              (map (comp #(.getPath %) c/tmp-file))
                              (cons threejs-path)
                              (clojure.string/join ","))]
        (util/info "Generating externs.\n")
        (io/make-parents externs-file)
        (io/copy package-file (io/file tmp "package.json"))
        (binding [boot.util/*sh-dir* (str tmp)]
          ((sh "npm" "install" "externs-generator"))
          ((sh "node_modules/externs-generator/bin/extern"
               "-f" input-string
               "-n" "THREE"
               "-o" (.getPath externs-file))))
        (-> fileset (c/add-resource tmp) c/commit!)))))