Skip to content

Repeat

Name - Description Default Type
<input> The input will be passed to both the action and the :Until condition if used. Any
<output> The output of this shard will be its input. Any
Action The shards to repeat. None Shard[Shard]
Times How many times we should repeat the action. 0 Int&Int
Forever If we should repeat the action forever. false Bool
Until Optional shards to use as predicate to continue repeating until it's true None Shard[Shard]

Repeat an action a given number of times or until a condition is no longer true.

Examples

1
2
3
(Repeat
 (-> (Msg "Hello"))
 :Times 5)
[info] [shards/General/Repeat/1.edn] Hello
[info] [shards/General/Repeat/1.edn] Hello
[info] [shards/General/Repeat/1.edn] Hello
[info] [shards/General/Repeat/1.edn] Hello
[info] [shards/General/Repeat/1.edn] Hello

 

1
2
3
4
5
6
7
0 >= .n
(Repeat
 (->
  .n (Log "Counting")
  (Math.Inc .n))
 :Forever true
 :Until (-> .n (IsMore 9)))
[info] [shards/General/Repeat/2.edn] Counting: 0
[info] [shards/General/Repeat/2.edn] Counting: 1
[info] [shards/General/Repeat/2.edn] Counting: 2
[info] [shards/General/Repeat/2.edn] Counting: 3
[info] [shards/General/Repeat/2.edn] Counting: 4
[info] [shards/General/Repeat/2.edn] Counting: 5
[info] [shards/General/Repeat/2.edn] Counting: 6
[info] [shards/General/Repeat/2.edn] Counting: 7
[info] [shards/General/Repeat/2.edn] Counting: 8
[info] [shards/General/Repeat/2.edn] Counting: 9