Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Elm/Kernel/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function _Debug_toAnsiString(ansi, value)
return _Debug_stringColor(ansi, '<' + value.byteLength + ' bytes>');
}

if (typeof File === 'function' && value instanceof File)
if (typeof File !== 'undefined' && value instanceof File)
{
return _Debug_internalColor(ansi, '<' + value.name + '>');
}
Expand Down
17 changes: 17 additions & 0 deletions src/Elm/Kernel/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ var _List_map5 = F6(function(f, vs, ws, xs, ys, zs)
return _List_fromArray(arr);
});

var _List_append = F2(_List_ap);

function _List_ap(xs, ys)
{
if (!xs.b)
{
return ys;
}
var root = _List_Cons(xs.a, ys);
xs = xs.b
for (var curr = root; xs.b; xs = xs.b) // WHILE_CONS
{
curr = curr.b = _List_Cons(xs.a, ys);
}
return root;
}

var _List_sortBy = F2(function(f, xs)
{
return _List_fromArray(_List_toArray(xs).sort(function(a, b) {
Expand Down
14 changes: 2 additions & 12 deletions src/Elm/Kernel/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,6 @@ function _Utils_ap(xs, ys)
return xs + ys;
}

// append Lists
if (!xs.b)
{
return ys;
}
var root = __List_Cons(xs.a, ys);
xs = xs.b
for (var curr = root; xs.b; xs = xs.b) // WHILE_CONS
{
curr = curr.b = __List_Cons(xs.a, ys);
}
return root;
// append Lists
return __List_ap(xs, ys);
}
49 changes: 29 additions & 20 deletions src/List.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ element (starting at zero).
-}
indexedMap : (Int -> a -> b) -> List a -> List b
indexedMap f xs =
map2 f (range 0 (length xs - 1)) xs
reverse (indexedMapHelper 0 f xs [])


indexedMapHelper : (Int -> a -> b)->Int -> List a -> List b -> List b
indexedMapHelper fn index list result =
case list of
[] ->
result

x :: xs ->
indexedMapHelper fn (index + 1) xs (cons (fn index x) result)


{-| Reduce a list from the left.
Expand Down Expand Up @@ -198,7 +208,7 @@ foldrHelper fn acc ctr ls =
d :: r4 ->
let
res =
if ctr > 500 then
if ctr > 1000 then
foldl fn acc (reverse r4)
else
foldrHelper fn acc (ctr + 1) r4
Expand Down Expand Up @@ -227,17 +237,16 @@ from an untrusted source and you want to turn them into numbers:
-}
filterMap : (a -> Maybe b) -> List a -> List b
filterMap f xs =
foldr (maybeCons f) [] xs


maybeCons : (a -> Maybe b) -> a -> List b -> List b
maybeCons f mx xs =
case f mx of
Just x ->
cons x xs
let
helper mx acc =
case f mx of
Just x ->
cons x acc

Nothing ->
xs
Nothing ->
acc
in
foldr helper [] xs


-- UTILITIES
Expand Down Expand Up @@ -363,13 +372,8 @@ product numbers =
You can also use [the `(++)` operator](Basics#++) to append lists.
-}
append : List a -> List a -> List a
append xs ys =
case ys of
[] ->
xs

_ ->
foldr cons ys xs
append =
Elm.Kernel.List.append


{-| Concatenate a bunch of lists into a single list:
Expand All @@ -387,7 +391,12 @@ concat lists =
-}
concatMap : (a -> List b) -> List a -> List b
concatMap f list =
concat (map f list)
let
helper val acc =
append (f val) acc
in
foldr helper [] list



{-| Places the given value between all members of the given list.
Expand Down