Skip to content

Instantly share code, notes, and snippets.

@anton-trunov
Created May 20, 2017 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anton-trunov/4394f3edf07a9ccc930e454491a2e257 to your computer and use it in GitHub Desktop.
Save anton-trunov/4394f3edf07a9ccc930e454491a2e257 to your computer and use it in GitHub Desktop.
-- http://stackoverflow.com/questions/44079181/idris-vect-fromlist-usage-with-generated-list
total
takeExact : (n : Nat) -> (xs : List a) -> Maybe (Vect n a)
takeExact Z xs = Just []
takeExact (S n) [] = Nothing
takeExact (S n) (x :: xs) with (takeExact n xs)
takeExact (S n) (x :: xs) | Nothing = Nothing
takeExact (S n) (x :: xs) | (Just v) = Just (x :: v)
total
window : (n : Nat) -> List a -> List (Vect n a)
window n xs with (takeExact n xs)
window n xs | Nothing = []
window n [] | (Just ys) = []
window n (x :: xs) | (Just ys) = ys :: window n xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment