Fork me on GitHub
#beginners
<
2022-10-23
>
Tirion00:10:57

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?

hiredman00:10:41

There is no requirement to assoc anything in the start function

hiredman00:10:46

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

hiredman00:10:54

The default start function does nothing

hiredman00:10:40

Start can also return a completing different object as well

cddr10:10:09

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.

Jim Strieter16:10:33

(rest some-vector) takes O(1) time right?

pppaul17:10:42

I'm pretty sure that you can implement a type that works with rest that would result in rest being any runtime complexity.

pppaul17:10:50

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.

pppaul17:10:19

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

🙌 1
Alex Miller (Clojure team)21:10:38

in short, the answer is yes

Alex Miller (Clojure team)21:10:00

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)

Jim Strieter11:10:20

some-vec is a built in Clojure vector, so it sounds like yes. Thanks everybody!