RobTrew/prelude-jxa

Missing application of snd inside `indexedTree`

Closed this issue · 5 comments

prelude-jxa/jsPrelude.js

Lines 1951 to 1961 in 5e84ff4

// indexedTree :: Int -> Tree a -> Tree (a, Int)
const indexedTree = rootIndex =>
// A tree in which each root value
// is paired with a top-down
// left-right index, where the root node
// starts at the supplied rootIndex;
mapAccumLTree(
i => x => [1 + i, [x, {
index: i
}]]
)(rootIndex);

First issue I am opening. Seems very convenient :-)

Thanks ! I've added an index into the tuple.

Good. However, it doesn't return a type Tree (a, Int), yet. This function:

mapAccumLTree(
    i => x => [1 + i, [x, {
        index: i
    }]]
)(rootIndex)

returns

(Traversable t, Enum b, Num b) => t a -> (b, t (a, b))

so, getting the second component of that type results in a type error, I think.

I might suggest composing snd and mapAccumLTree.

Thanks ! eta-expanded now.

(Always hubris to edit without testing – I must try to learn that :-))

Works perfectly ! Closing the issue :-)