Skip to content

Commit 2bbef76

Browse files
items :: FileList -> Array File
1 parent 9695676 commit 2bbef76

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ package-lock.json
66
/bower_components/
77
/node_modules/
88
/output/
9+
*.swp

src/Web/File/FileList.purs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ module Web.File.FileList
22
( FileList
33
, length
44
, item
5+
, items
56
) where
67

78
import Prelude
89

9-
import Data.Maybe (Maybe)
10+
import Data.Maybe (Maybe(..))
1011
import Data.Nullable (Nullable, toMaybe)
12+
import Data.Array (snoc)
13+
import Data.Tuple (Tuple(..))
1114
import Web.File.File (File)
1215

1316
foreign import data FileList :: Type
@@ -20,3 +23,12 @@ foreign import _item :: Int -> FileList -> Nullable File
2023
-- | Get `File` at the certain position
2124
item :: Int -> FileList -> Maybe File
2225
item i = toMaybe <<< _item i
26+
27+
items :: FileList -> Array File
28+
items fl = untilNothing (\c fs -> Tuple (c + 1) <<< snoc fs <$> item c fl) 0 mempty
29+
30+
untilNothing :: forall a b. (a -> b -> Maybe (Tuple a b)) -> a -> b -> b
31+
untilNothing f x y = let m = f x y in
32+
case m of (Just (Tuple x' y')) -> untilNothing f x' y'
33+
Nothing -> y
34+

0 commit comments

Comments
 (0)