Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non empty #4

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
36 changes: 36 additions & 0 deletions src/Data/Array/NonEmpty/Internal.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(library (Data.Array.NonEmpty.Internal foreign)
(export foldr1Impl
foldl1Impl
traverse1Impl)
(import (only (rnrs base) define lambda list cons let if quote)
anttih marked this conversation as resolved.
Show resolved Hide resolved
(only (chezscheme) fx- fx< fx>= fx1- fx1+)
(prefix (purs runtime lib) rt:)
(prefix (purs runtime srfi :214) srfi:214:))

(define foldr1Impl
(lambda (f xs)
(let loop ([acc (srfi:214:flexvector-back xs)]
[i (fx- (rt:array-length xs) 2)])
(if (fx>= i 0)
(loop ((f (rt:array-ref xs i)) acc) (fx1- i))
acc))))

(define foldl1Impl
(lambda (f xs)
(let loop ([acc (rt:array-ref xs 0)] [i 1])
(if (fx< i (rt:array-length xs))
(loop ((f acc) (rt:array-ref xs i)) (fx1+ i))
acc))))

(define traverse1Impl
(lambda (apply map f)

(define kons (lambda (x) (lambda (ys) (cons x ys))))

(lambda (array)
((map srfi:214:list->flexvector)
(srfi:214:flexvector-fold-right
(lambda (s x) ((apply ((map kons) (f x))) s))
((map list) (f (srfi:214:flexvector-back array)))
(srfi:214:flexvector-copy array 0 (fx1- (rt:array-length array))))))))
)
4 changes: 2 additions & 2 deletions test/Test/Data/Array/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Effect (Effect)
import Effect.Console (log)
import Partial.Unsafe (unsafePartial)
import Test.Assert (assert)
import Test.Data.UndefinedOr (defined, undefined)
-- import Test.Data.UndefinedOr (defined, undefined)

testNonEmptyArray :: Effect Unit
testNonEmptyArray = do
Expand Down Expand Up @@ -247,7 +247,7 @@ testNonEmptyArray = do

log "sort should reorder a list into ascending order based on the result of compare"
assert $ NEA.sort (fromArray [1, 3, 2, 5, 6, 4]) == fromArray [1, 2, 3, 4, 5, 6]
assert $ NEA.sort (fromArray [defined 1, undefined, defined 2]) == fromArray [undefined, defined 1, defined 2]
-- assert $ NEA.sort (fromArray [defined 1, undefined, defined 2]) == fromArray [undefined, defined 1, defined 2]

log "sortBy should reorder a list into ascending order based on the result of a comparison function"
assert $ NEA.sortBy (flip compare) (fromArray [1, 3, 2, 5, 6, 4]) == fromArray [6, 5, 4, 3, 2, 1]
Expand Down
31 changes: 0 additions & 31 deletions test/Test/Data/UndefinedOr.js

This file was deleted.

17 changes: 0 additions & 17 deletions test/Test/Data/UndefinedOr.purs

This file was deleted.

4 changes: 2 additions & 2 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Test.Data.Array (testArray)
import Test.Data.Array.Partial (testArrayPartial)
import Test.Data.Array.ST (testArrayST)
import Test.Data.Array.ST.Partial (testArraySTPartial)
-- import Test.Data.Array.NonEmpty (testNonEmptyArray)
import Test.Data.Array.NonEmpty (testNonEmptyArray)

main :: Effect Unit
main = do
testArray
testArrayST
testArrayPartial
testArraySTPartial
-- testNonEmptyArray
testNonEmptyArray
Loading