Вы можете использовать partition
или partition-all
в зависимости от того, заинтересованы ли вы также в последних "non- tri -грамм":
user=> (doc partition)
-------------------------
clojure.core/partition
([n coll] [n step coll] [n step pad coll])
Returns a lazy sequence of lists of n items each, at offsets step
apart. If step is not supplied, defaults to n, i.e. the partitions
do not overlap. If a pad collection is supplied, use its elements as
necessary to complete last partition upto n items. In case there are
not enough padding elements, return a partition with less than n items.
(user=> (doc partition-all)
-------------------------
clojure.core/partition-all
([n] [n coll] [n step coll])
Returns a lazy sequence of lists like partition, but may include
partitions with fewer than n items at the end. Returns a stateful
transducer when no collection is provided.
Например
user=> (partition 3 1 "This is a string")
((\T \h \i)
(\h \i \s)
(\i \s \space)
(\s \space \i)
(\space \i \s)
(\i \s \space)
(\s \space \a)
(\space \a \space)
(\a \space \s)
(\space \s \t)
(\s \t \r)
(\t \r \i)
(\r \i \n)
(\i \n \g))
Чтобы вернуть строки, присоедините символы:
user=> (map clojure.string/join (partition 3 1 "This is a string"))
("Thi"
"his"
"is "
"s i"
" is"
"is "
"s a"
" a "
"a s"
" st"
"str"
"tri"
"rin"
"ing")
или замените на partition-all
соответственно:
user=> (map clojure.string/join (partition-all 3 1 "This is a string"))
("Thi"
; ...
"rin"
"ing"
"ng" ; XXX
"g") ; XXX