Skip to content

Commit

Permalink
progress-bars.models: adding map/each/reduce with-progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Dec 7, 2024
1 parent 440dec8 commit a75eced
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions extra/progress-bars/models/models.factor
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
! Copyright (C) 2011 Doug Coleman.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors calendar fonts io io.files io.files.info kernel
math models models.arrow namespaces progress-bars threads
ui.gadgets.labels ui.gadgets.panes ;
math models models.arrow namespaces progress-bars sequences
threads ui.gadgets.labels ui.gadgets.panes ;
IN: progress-bars.models

SYMBOL: progress-bar
Expand Down Expand Up @@ -40,4 +40,19 @@ SYMBOL: file-size
] with-progress-bar ; inline

: with-progress-display ( quot -- )
'[ \ progress-bar get 50 <progress-display> gadget. @ ] with-progress-bar ; inline
[ \ progress-bar get 50 <progress-display> gadget. call ] with-progress-bar ; inline

: map-with-progress-bar ( seq quot -- seq' )
[ dup length 1 - ] dip '[
[ _ / set-progress-bar @ ] map-index
] with-progress-display ; inline

: each-with-progress-bar ( seq quot -- )
[ dup length 1 - ] dip '[
[ _ / set-progress-bar @ ] each-index
] with-progress-display ; inline

: reduce-with-progress-bar ( seq identity quot -- )
[ over length 1 - ] dip '[
[ _ / set-progress-bar @ ] reduce-index
] with-progress-display ; inline

0 comments on commit a75eced

Please sign in to comment.