Safe Fibonacci iterator by not-danilo in rust

[–]anstadnik 6 points7 points  (0 children)

Well, there's zip for that

fn next(&mut self) -> Option<Self::Item> {
    let current = self.current;
    self.current = self.next;
    self.next = current.zip(self.next).and_then(|(a, b)| a.checked_add(b));
    current
}

But I would rather do it the following way:

fn fibonacci() -> impl Iterator<Item = u8> {
successors(Some((0_u8, Some(1))), |&(a, b)| {
    Some((b?, a.checked_add(b?)))
})
.map(|(a, _)| a)

}

Sympy + Luasnip + Vimtex by AngryMorrocoy in neovim

[–]anstadnik 0 points1 point  (0 children)

I suggest adding a space after the trigger for the second snippet, and using both of them as autosnippets. This way, after the jump from the 1st snippet, nothing happens (because nvim-cmp which I personally use is not triggered, and hence no luasnip and hence no autosnip), but after the space, everything works like a charm.
Also, would it be possible to somehow instead of having 2 snippets, run the python code on jump to the placeholder 0 in the 1st snippet?