This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-23
Channels
- # announcements (3)
- # aws (2)
- # babashka (31)
- # beginners (14)
- # calva (14)
- # cider (4)
- # clj-kondo (1)
- # clojure (24)
- # clojure-europe (18)
- # clojure-gamedev (4)
- # clojure-nl (3)
- # clojure-norway (23)
- # clojurescript (24)
- # core-typed (23)
- # data-science (9)
- # datomic (1)
- # emacs (15)
- # events (4)
- # gratitude (3)
- # introduce-yourself (1)
- # leiningen (9)
- # lsp (65)
- # membrane (39)
- # music (1)
- # nbb (1)
- # obb (8)
- # reitit (17)
- # releases (1)
- # tree-sitter (2)
- # vim (28)
- # xtdb (3)
Hi all I'm a beginner and I have a question I could use some help with. When we use the component model, in the start function of the component, why do we always need to assoc something? Everywhere I've seen online it seems to be required. On my app it seems that it will not run properly unless I assoc a value. Is it possible to be done without assoc anything there?
You can see the default start function here https://github.com/stuartsierra/component/blob/master/src/com/stuartsierra/component.cljc#L17 which is used for anything that doesn't have a more specific extension of Lifecycle
You don’t necessarily need to assoc something but the return value ends up as part of the “system”. If your component acquires a handle to communicate with some external system and you’d like to be able to clean that up when you stop the component, you need to include it in the return value.
(rest some-vector) takes O(1) time right?
I'm pretty sure that you can implement a type that works with rest
that would result in rest
being any runtime complexity.
https://journal.artfuldev.com/implementing-a-custom-collection-type-in-clojure-the-leftist-heap-a-persistent-priority-queue-2917b20a069 this is a blog discussing the topic.
but, if some-vector
is a clojure vector, then since it's a persistent data structure, it should be able to get it's first level children nodes pretty fast. persistent data structures don't do full collection copying when modified.
https://en.wikipedia.org/wiki/Persistent_data_structure turns out just being a persistent data structure isn't enough to know how it's built. clojure uses "Persistent hash array mapped trie" which is referenced in this article
in short, the answer is yes
in long, the answer depends on the data structure. lists or seqs will be O(1) but data structures like vectors, maps, and sets need to produce a seq view and step into it which is often O log base 32 (which is effectively constant)
some-vec is a built in Clojure vector, so it sounds like yes. Thanks everybody!