File tree 4 files changed +17
-11
lines changed
4 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 18
18
],
19
19
"dependencies" : {
20
20
"purescript-either" : " ^2.0.0" ,
21
- "purescript-maybe" : " ^2.0.0"
21
+ "purescript-maybe" : " ^2.0.0" ,
22
+ "purescript-tuples" : " ^3.0.0"
22
23
},
23
24
"devDependencies" : {
24
25
"purescript-assert" : " ^2.0.0" ,
Original file line number Diff line number Diff line change @@ -146,10 +146,12 @@ exports.split = function (sep) {
146
146
147
147
exports . _splitAt = function ( just ) {
148
148
return function ( nothing ) {
149
- return function ( i ) {
150
- return function ( s ) {
151
- return i >= 0 && i < s . length ?
152
- just ( [ s . substring ( 0 , i ) , s . substring ( i ) ] ) : nothing ;
149
+ return function ( tuple ) {
150
+ return function ( i ) {
151
+ return function ( s ) {
152
+ return i >= 0 && i < s . length ?
153
+ just ( tuple ( s . substring ( 0 , i ) ) ( s . substring ( i ) ) ) : nothing ;
154
+ } ;
153
155
} ;
154
156
} ;
155
157
} ;
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import Prelude
41
41
import Data.Maybe (Maybe (..), isJust )
42
42
import Data.Newtype (class Newtype )
43
43
import Data.String.Unsafe as U
44
+ import Data.Tuple (Tuple (..))
44
45
45
46
-- | A newtype used in cases where there is a string to be matched.
46
47
newtype Pattern = Pattern String
@@ -232,14 +233,15 @@ foreign import count :: (Char -> Boolean) -> String -> Int
232
233
foreign import split :: Pattern -> String -> Array String
233
234
234
235
-- | Returns the substrings of split at the given index, if the index is within bounds.
235
- splitAt :: Int -> String -> Maybe (Array String )
236
- splitAt = _splitAt Just Nothing
236
+ splitAt :: Int -> String -> Maybe (Tuple String String )
237
+ splitAt = _splitAt Just Nothing Tuple
237
238
238
239
foreign import _splitAt :: (forall a . a -> Maybe a )
239
240
-> (forall a . Maybe a )
241
+ -> (forall a b . a -> b -> Tuple a b )
240
242
-> Int
241
243
-> String
242
- -> Maybe (Array String )
244
+ -> Maybe (Tuple String String )
243
245
244
246
-- | Converts the string into an array of characters.
245
247
foreign import toCharArray :: String -> Array Char
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Control.Monad.Eff (Eff)
6
6
import Control.Monad.Eff.Console (CONSOLE , log )
7
7
8
8
import Data.Maybe (Maybe (..), isNothing )
9
+ import Data.Tuple (Tuple (..))
9
10
import Data.String
10
11
11
12
import Test.Assert (ASSERT , assert )
@@ -161,9 +162,9 @@ testString = do
161
162
162
163
log " splitAt"
163
164
assert $ splitAt 1 " " == Nothing
164
- assert $ splitAt 0 " a" == Just [ " " , " a" ]
165
- assert $ splitAt 1 " ab" == Just [ " a" , " b" ]
166
- assert $ splitAt 3 " aabcc" == Just [ " aab" , " cc" ]
165
+ assert $ splitAt 0 " a" == Just ( Tuple " " " a" )
166
+ assert $ splitAt 1 " ab" == Just ( Tuple " a" " b" )
167
+ assert $ splitAt 3 " aabcc" == Just ( Tuple " aab" " cc" )
167
168
assert $ splitAt (-1 ) " abc" == Nothing
168
169
169
170
log " toCharArray"
You can’t perform that action at this time.
0 commit comments