add Indexl and indexr#83
Conversation
| indexr :: forall a f. Foldable f => Int -> f a -> Maybe a | ||
| indexr idx = _.elem <<< foldr go { elem: Nothing, pos: 0 } | ||
| where | ||
| go elem cursor = |
There was a problem hiding this comment.
I could create non-exported indexGo function and use it in in both places (in one I would need to flip it)
|
last commit changed output from: var go = function (v) {
return function (v1) {
if (v.pos === idx) {
return {
pos: v.pos + 1 | 0,
elem: new Data_Maybe.Just(v1)
};
};
var $119 = {};
for (var $120 in v) {
if ({}.hasOwnProperty.call(v, $120)) {
$119[$120] = v[$120];
};
};
$119.pos = v.pos + 1 | 0;
return $119;
};
};to var go = function (cursor) {
return function (elem1) {
if (cursor.elem instanceof Data_Maybe.Just) {
return cursor;
};
var $115 = cursor.pos === idx;
if ($115) {
return {
elem: new Data_Maybe.Just(elem1),
pos: cursor.pos
};
};
return {
pos: cursor.pos + 1 | 0,
elem: cursor.elem
};
};
}; |
|
@paf31 it's ready |
|
Wouldn't this sort of thing be better suited to |
|
I do think it makes sense to add this. A |
|
Maybe with a warning that people using this on, say, a |
|
I'm not sure. It would be quite annoying, I think, for the behavior of say, an |
|
I think changing |
|
I'm not saying that it's the fault of the function, I'm saying the order of a fold should be considered part of the observable behavior of a |

fixes #82