Public Vars

Back

max-key (clj)

(source)

function

(max-key k x) (max-key k x y) (max-key k x y & more)
Returns the x for which (k x), a number, is greatest. If there are multiple such xs, the last one is returned.

Examples

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/max-key (t/All [x] [[x :-> t/Num] (t/+ x) :-> x])
cc/min-key (t/All [x] [[x :-> t/Num] (t/+ x) :-> x])
yetanalytics/dave
(ns com.yetanalytics.dave.ui.app.workbook.data
  (:require [re-frame.core :as re-frame]
            [com.yetanalytics.dave.workbook.data :as data]
            [com.yetanalytics.dave.workbook.data.state :as state]
            [com.yetanalytics.dave.workbook.data.lrs.client
             :as lrs-client]
            [clojure.core.async :as a :include-macros true]
            [clojure.spec.alpha :as s]
            [goog.string :refer [format]]
            [goog.string.format]))

(re-frame/reg-event-fx
 ::set-state
 ;; called for a data source when loading is complete.
 ;; funcs check if their state is = to this before deriving results.
 (fn [{:keys [db]}
      [_
       workbook-id
       new-state
       force?]]
   (let [new-db (assoc-in
                 (if force?
                   (assoc-in db
                             [:workbooks
                              workbook-id
                              :data
                              :state]
                             new-state)
                   (update-in db
                              [:workbooks
                               workbook-id
                               :data
                               :state]
                              (fnil
                               (partial max-key :statement-idx)
                               state/init-state)
                              new-state))
                 [:workbooks
                  workbook-id
                  :data
                  :loading?]
                 false)]
     {:db new-db}
     ;; here is where you would fire off reactive results, which we're currently not doing
     #_(cond-> {:db new-db}
       (not= db new-db)
       (assoc :dispatch-n [[:workbook.question.function/result-all!
                            workbook-id]
                           [:db/save]])))))