Public Vars

Back

odd? (clj)

(source)

function

(odd? n)
Returns true if n is odd, throws an exception if n is not an integer

Examples

clojure
(ns clojure.test-clojure.reducers
  (:require [clojure.core.reducers :as r]
            [clojure.test.generative :refer (defspec)]
            [clojure.data.generators :as gen])
  (:use clojure.test))

(defequivtest test-filter
  [filter r/filter #(into [] %)]
  [even? odd? #(< 200 %) identity])
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/even? [t/AnyInteger :-> t/Bool]
cc/odd? [t/AnyInteger :-> t/Bool]
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure.jvm
  "JVM-specific type annotations for the base Clojure distribution."
  (:require [typed.clojure :as t]
            [typed.clojure.jvm :refer [override-classes]]
            clojure.core.typed)
  (:import (clojure.lang Named IMapEntry AMapEntry Seqable
                         LazySeq PersistentHashSet PersistentTreeSet PersistentTreeMap PersistentList APersistentVector
                         APersistentSet IPersistentSet IPersistentMap IPersistentVector
                         APersistentMap IDeref ISeq IPersistentCollection
                         ILookup Indexed Associative IPersistentStack PersistentVector Cons
                         IPersistentList IRef ARef Reversible
                         ITransientCollection ITransientSet ITransientAssociative ITransientMap
                         ITransientVector PersistentHashMap Reduced MultiFn Sorted)
           (java.util Collection RandomAccess)))

; 1. what is the variance of the dispatch function? covariant?
;
;   (ann f (MultiFn [t/Int -> t/Int] [t/Int -> Bool]))
;   (defmulti f even?)
;
;   ; make return types less specific -- seems ok. just means
;   ; we can infer less in defmethod's.
;   (ann-form f (MultiFn [t/Int -> t/Any] [t/Int -> t/Any]))
;
;   (ann g (MultiFn [t/Int -> t/Int] [t/Int -> Bool]))
;   (defmulti g odd?)
;
; 2. what bound do we want on `f` and `d`?
;   ; say if we don't have `d`'s lower bound as EveryIFn..
;   (ann f (MultiFn .. ':a))
;   (defmulti f :a)
;
;   (ann g (MultiFn .. (ToIFn ':a)))
;   (defmulti g (fn [a] (:a a)))
;
;   ; is this desirable? let's use the lower bound, since we can always
;   ; make the type more permissive later.
;   (ann-form f (TypeOf g)) ;ok
;   (ann-form g (TypeOf f)) ;fails
borkdude/flycheck-clj-kondo
(ns cond-without-else1
  (:refer-clojure :exclude [cond])
  (:require [clojure.core :as c]))

;; this one should not be caught:
(cond
  (odd? n) 1
  :else 2)
logaan/promise-stream
(ns promise-stream.pstream-test
  (:use-macros [promise-stream.macros :only [for-pstream]])
  (:use [jayq.util :only [log]] 
        [promise-stream.pstream :only
         [closed-pstream open-pstream append! close! reduce* map* mapd* concat*
          with-open-pstream mapcat* count* resolves-within?
          pairwise-traverse zip* promise fmap filter* rests* reductions* doall*
          dorun*]])
  (:require [jayq.core :as jq]
            [promise-stream.pcell :as pc]
            [clojure.core.reducers :as r]))

(jq/done
  (reduce (fmap conj) (promise [])
          (filter* (comp promise odd?) (closed-pstream 1 2 3 4)))
  #(assert (= [1 3] %)))
gerritjvv/fmap-clojure
(ns fmap-clojure.lens-tests
  (:require
    [fmap-clojure.core :refer :all]
    [fmap-clojure.lens :refer :all]
    [midje.sweet :as midje]))


             (-> [3 4 5] (view (only odd?))) midje/=> '(3 5)
             (-> [3 4 5] (update (only odd?) inc)) midje/=> [4 4 6]
             (-> [3 4 5] (put (only odd?) 7)) midje/=> [7 4 7]))