More generally, you are asking for an expressive way to make out the sequence. Of course, there are many parsing libraries for Clojure, but many of them make up parsing lexing (there may be good reasons for this in terms of performance optimization), and therefore can only be used for strings. You may need to search outside the toolbox to find a parser that allows you to lex as a separate issue.
Take, for example, The Parsatron (weighs only 262 locks)
(require '[the.parsatron ; sampling of available combinators :refer [run token attempt many times choice always never >> eof]]) (defn matches? [parser input] (run (choice (attempt (>> parser (eof) (always true))) (always false)) input))
Now define your template
(def odds-and-evens (>> (many (token odd?)) (times 2 (token even?))))
And check
(matches? odds-and-evens [1 1 2 2]) ;=> true (matches? odds-and-evens [1 1 1 2 2]) ;=> true (matches? odds-and-evens [1 1 2 2 2]) ;=> false (matches? odds-and-evens [1 1 2]) ;=> false
Here you can add sugar to indicate your pattern as you wish.
source share