hyperfiddle

2025-08-29T16:25:12.202469Z

I noticed that I can't do this: (map ElectricFn some-values), the fn is not called, no reactivity, silent failure. Is there any workaround except using e/for?

Dustin Getz (Hyperfiddle) 2025-08-30T11:40:41.887949Z

all electric defs need to be in a .cljc file, but host clojure/script functions do not

Dustin Getz (Hyperfiddle) 2025-08-30T11:45:52.690989Z

i've added a line to the tutorial to clarify this, thanks

Dustin Getz (Hyperfiddle) 2025-08-30T11:51:21.938959Z

Generally speaking, I don't think you should be doing "filtering" operations in Electric, for a couple reasons • filtering is performance sensitive • performance sensitive means no latency - there cannot be client/server transfer in filtering • performance sensitive means fast on large collections - which Electric is not, Electric is like 100x slower than regular Clojure for imperative programs such as looping over a large collection - due to all the overhead of reactivity, the network runtime, the object lifecycle, etc • really the only thing Electric is excellent at is distributing view state from backend to frontend, it is not a general purpose language, the host language fills that role instead

✍️ 2
Dustin Getz (Hyperfiddle) 2025-08-30T12:00:23.654519Z

even e/for is designed for small "differential collections" - an assumption of any client/server system is that the client has limited memory, you never want to send huge collections over the wire (the client then has to deserialize, parse, hold them in memory, loop over them). Most web apps paginate, electric uses virtual scroll. you only want enough in memory to draw the current viewport

oλv 2025-08-29T16:40:04.597489Z

You can't call Electric functions like host functions, they have different calling conventions. What are you trying to achieve? 😄

2025-08-29T16:50:43.293019Z

I have a set of input filtering functions, and it felt natural to make some of them Electric, as they compare input values. And I map over them, to filter an input value. I know how to do this without Electric fns, just wondering what is possible, and how would it look.

oλv 2025-08-29T16:54:30.451149Z

Well, it depends 😅

oλv 2025-08-29T16:54:50.680689Z

If you need to materialize your sequence, you can use e/as-vec

oλv 2025-08-29T16:58:56.679379Z

Could you show some more (pseudo)code?

2025-08-29T17:01:16.006809Z

(e/defn ComposeInputFilters
"Returns the first error keyword from filter-fns applied to user-input or nil"
  [filter-fns user-input]
  (->> filter-fns
       (map #(% user-input))
       (some identity)))
Ideally, I would like to have both Electric and usual fns in filter-fns, but I know it's not possible.

oλv 2025-08-29T17:05:52.834919Z

Does your filter-fns need to be cross-site (run on both client and server)? Otherwise, I would make this regular Clojure code.

oλv 2025-08-29T17:08:00.261419Z

Clojure function are more reusable in the sense that it's easy to lift a Clojure fn to an Electric fn, but not so straight forward the other way

2025-08-29T17:08:53.742969Z

No, there's no need, and I already made it work with regular Clojure. I had an Electric fn which generated a regular filter-fn. Just trying to do it differently, maybe a bit more elegant.

👍 1
2025-08-29T17:20:48.648659Z

Another question then, when I make all filter-fns Electric, and pass them like this: [shui/NotANumber? shui/Negative? MaxTc<MinTc?] The locally defined fn is passed fine, and I can use it in e/for:

(e/for [F (e/diff-by {} FilterFns)]
              (F user-input)) 
But the other two have different types, and e/for breaks when I add them. Is this because they are defined in .cljs file, or because they are not local? Is there an easy fix?

2025-08-29T18:37:29.814189Z

Nvm, I made it work