Fork me on GitHub
#clojure-europe
<
2020-11-08
>
pez10:11:19

Good morning! I'm trying to understand why

(reduce str "1") => \1

borkdude11:11:56

That's weird. But (reduce str "" "1") does work. Btw, (apply str ...) might be better so there's only one StringBuilder

otfrom12:11:09

is it going to assume that the string is a seq of characters?

slipset12:11:18

I think you’re seeing a couple of things. If I remember correctly, reduce will not invoke the reducing fn if there is only one element in the list

slipset12:11:01

And, as discussed previously, a string is considered a sea of chars, as @U0525KG62 points lit

borkdude12:11:17

@U04V5VAUN You're correct.

(reduce - [1])
1

slipset12:11:32

There is a mailing list entry (or something) somewhere where Rich regrets the two arity version of reduce for several reasons.

borkdude12:11:51

Could make a clj-kondo rule for this: always provide an identity element

borkdude12:11:16

If you could point me to the Rich entry on this, could post it in an issue

pez15:11:37

Thanks. I didn't run into trouble with this. I was just trying to understand reduce a bit better and one of my experiments gave me that funny result.

val_waeselynck15:11:43

Hint: the other name for String is CharSequence ;) and reduce with this arity assumes that an element combined to no other reduces to itself.

👍 3
otfrom17:11:00

anyone here had a play with flow-storm-debugger? https://github.com/jpmonettas/flow-storm-debugger