Fork me on GitHub
#squint
<
2022-08-29
>
borkdude09:08:52

Added two new functions, looking pretty sweet if you ask me:

export function partial(f, ...xs) {
  return function (...args) {
    return f(...xs, ...args);
  };
}

export function cycle(coll) {
  return new LazyIterable(function* () {
    while (true) yield* coll;
  });
}

borkdude 1
Prabhjot Singh11:08:18

looking great. I was looking at the implementation of take-while and curious if there is any particular reason to use manual iterator rather than using for..of

Prabhjot Singh11:08:14

or is it just preference.

borkdude11:08:15

good point, probably not

borkdude12:08:07

@prabnz Changed it to:

export function take_while(pred, coll) {
  return new LazyIterable(function* () {
    for (const o of iterable(coll)) {
      if (pred(o)) yield val;
      else return;
    }
  });
}

Prabhjot Singh12:08:41

wow, you are very fast. looks good.

Prabhjot Singh12:08:19

also I am wondering if the minifiers actually minify code like new LazyIterable. If not then maybe wrap it in a function to reduce code size.

borkdude12:08:46

also simplified drop-while:

export function drop_while(pred, xs) {
  return new LazyIterable(function* () {
    let done_dropping = false;
    for (const o of iterable(xs)) {
      if (done_dropping) yield o;
      else if (!pred(o)) {
        yield o;
        done_dropping = true;
      }
    }
  });
}

borkdude12:08:28

@prabnz you mean a function lazy ?

Prabhjot Singh12:08:51

yes, but I am not sure if it will help with minification. I will do some experimentation

borkdude12:08:29

well, it will help at least us do less typing ;)

borkdude14:08:56

@prabnz I made the lazy constructor function now

borkdude18:08:35

Hmm, currently working on group-by and this makes me wonder if it should return an object or map, by default. lodash returns an object with the stringified key, which probably works best for interop with the rest of the stuff, rather than returning a Map by default

borkdude19:08:35

OTOH, this should probably work, as in CLJS, so Map would make sense:

$ ./node_cli.js -e '(prn (get (group-by odd? [1 2 3 4]) true))'
["0","1","2","3"]

borkdude19:08:28

Going with a map then, and if someone will change my mind, I'll be open to that!

borkdude19:08:52

Haha, wow, I got bitten by JS twice in the last half an hour:

const o in [1,2,3,4] vs const o of [1,2,3,4]
and: reusing a mutable array, so all vals in the group-by map were the same mutable collection:
const update_fn = (fnil conj_BANG_ [])
I guess I could have used conj instead of conj_BANG as well

borkdude19:08:28

but now it works as it should:

$ ./node_cli.js -e '(println (group-by odd? [1 2 3 4]))'
Map(2) { true => [ 1, 3 ], false => [ 2, 4 ] }