Skip to content

Commit

Permalink
add list length
Browse files Browse the repository at this point in the history
  • Loading branch information
eeue56 committed Jan 22, 2022
1 parent 921fe25 commit 14b3bc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/List.derw
@@ -1,6 +1,8 @@
import "./Maybe" exposing ( Maybe )

exposing (emptyList, map, filter, foldl, filterMap, append, reverse)
import "./List_kernel" exposing (kernelLength)

exposing (emptyList, map, filter, foldl, filterMap, append, reverse, length)

emptyList: List any
emptyList =
Expand Down Expand Up @@ -40,4 +42,8 @@ append xs ys =

reverse: List any -> List any
reverse xs =
xs.reverse()
xs.reverse()

length: List any -> number
length xs =
kernelLength xs
3 changes: 3 additions & 0 deletions src/List_kernel.ts
@@ -0,0 +1,3 @@
export function kernelLength(xs: any[]): number {
return xs.length;
}
12 changes: 9 additions & 3 deletions src/List_test.derw
@@ -1,7 +1,7 @@
exposing (testEmptyList, testMap, testFilter, testFoldl, testFilterMap, testAppend, testReverse)
exposing (testEmptyList, testMap, testFilter, testFoldl, testFilterMap, testAppend, testReverse, testLength)

import "./Test" exposing (equals)
import "./List" exposing (emptyList, map, filter, foldl, filterMap, append, reverse)
import "./List" exposing (emptyList, map, filter, foldl, filterMap, append, reverse, length)
import "./Maybe" exposing (Maybe, Just, Nothing)

testEmptyList: boolean -> void
Expand Down Expand Up @@ -96,4 +96,10 @@ testAppend a? =
testReverse: boolean -> void
testReverse a? =
reverse [ 1, 2 ]
|> equals [ 2, 1 ]
|> equals [ 2, 1 ]

testLength: boolean -> void
testLength a? =
[ 1, 2, 3 ]
|> length
|> equals 3

0 comments on commit 14b3bc3

Please sign in to comment.