-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds splittable class, split method for sequences and eq types
- Loading branch information
Showing
12 changed files
with
195 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(coalton-library/utils:defstdlib-package #:coalton-library/split | ||
(:use | ||
#:coalton | ||
#:coalton-library/builtin | ||
#:coalton-library/classes) | ||
(:local-nicknames | ||
(#:iter #:coalton-library/iterator) | ||
(#:types #:coalton-library/types)) | ||
(:export | ||
#:splittable | ||
#:split)) | ||
|
||
|
||
(in-package #:coalton-library/split) | ||
|
||
(named-readtables:in-readtable coalton:coalton) | ||
|
||
|
||
;;; | ||
;;; Split | ||
;;; | ||
|
||
(coalton-toplevel | ||
|
||
(define-class (Splittable :seq) | ||
"Sequence types that can be split by element equality." | ||
(split ((Eq :a) (types:runtimerepr :a) => :a -> (:seq :a) -> (iter:iterator (:seq :a)))))) | ||
|
||
|
||
|
||
;; TODO (Maybe): | ||
;; Add instance for Slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(cl:in-package #:coalton-native-tests) | ||
|
||
(coalton-toplevel | ||
(define *split-path* "wow/ok/dir/file.txt") | ||
|
||
(define *split-path-undotted* (make-list | ||
(make-list #\w #\o #\w #\/ #\o #\k #\/ #\d #\i #\r #\/ #\f #\i #\l #\e) | ||
(make-list #\t #\x #\t))) | ||
|
||
(define *split-path-unslashed* (make-list | ||
(make-list #\w #\o #\w) | ||
(make-list #\o #\k) | ||
(make-list #\d #\i #\r) | ||
(make-list #\f #\i #\l #\e #\. #\t #\x #\t)))) | ||
|
||
;;; | ||
;;; splitting lists | ||
;;; | ||
|
||
(define-test split-list () | ||
(is (== (iter:collect! (split:split #\. (iter:collect! (string:chars *split-path*)))) *split-path-undotted*)) | ||
(is (== (iter:collect! (split:split #\/ (iter:collect! (string:chars *split-path*)))) *split-path-unslashed*)) | ||
(is (== (iter:collect! (split:split 2 (make-list 1 2 3 4 2 5 2))) (make-list (make-list 1) | ||
(make-list 3 4) | ||
(make-list 5)))) | ||
(is (== (iter:collect! (split:split #\A (iter:collect! (string:chars "BANANA")))) | ||
(make-list (make-list #\B) | ||
(make-list #\N) | ||
(make-list #\N))))) | ||
|
||
;;; | ||
;;; splitting vectors | ||
;;; | ||
|
||
|
||
(define-test split-vector () | ||
(is (== (iter:collect! (split:split #\. (list->vec (iter:collect! (string:chars *split-path*))))) | ||
(map list->vec *split-path-undotted*))) | ||
(is (== (iter:collect! (split:split #\/ (list->vec (iter:collect! (string:chars *split-path*))))) | ||
(map list->vec *split-path-unslashed*)))) | ||
|
||
;;; | ||
;;; splitting vector | ||
;;; | ||
|
||
|
||
(coalton-toplevel | ||
|
||
(define (seq-num-list) | ||
(the (seq:Seq Integer) (iter:collect! (iter:up-to 10))))) | ||
|
||
(define-test split-seq () | ||
(is (== (the (List (seq:Seq Integer)) | ||
(iter:collect! (split:split 5 (seq-num-list)))) | ||
(make-list (the (seq:Seq Integer) (iter:collect! (iter:up-to 5))) | ||
(the (seq:Seq Integer) (iter:collect! (map (fn (x) (+ x 6)) (iter:up-to 4)))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters