Replies: 1 comment 4 replies
-
|
The above doesn't handle the case where Here's my suggestion: (defn partition-by
[f coll]
(def res @[])
(var prev nil)
(loop [e :in coll
:let [curr (f e)]]
(cond
(zero? (length res))
(array/push res @[e])
(= curr prev)
(array/push (last res) e)
(array/push res @[e]))
(set prev curr))
res) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I see that Janet already has
partition, but I wanted to be able to step through an array and create sub-arrays of it whenever the result of some(f e)(callingfon an elementeof the array) changed.I initially thought
fshould be a function of two args --- the curr and next array elems --- but it looks simpler if I just check to see if(f e)changes.Here's what I came up with:
How does that look? Suggestions for improvement appreciated.
Beta Was this translation helpful? Give feedback.
All reactions