Skip to content

Commit a273e03

Browse files
Simplify implementation of internal FFI function intercalate in Data.Show.Generic (#274)
* Simplify ffi implementation of Data.Show.Generic.intercalate. * Rename Data.Show.intercalate internal FFI function to match same function in Data.Show.Generic. * Add changelog entry for renaming internal FFI function join in Data.Show to intercalate. Co-authored-by: JordanMartinez <[email protected]>
1 parent ab5ebda commit a273e03

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Other improvements:
1919
- Added clearer docs for Prelude module (#270 by @JordanMartinez)
2020
- Clarify docs for `flip` (#271 by @JordanMartinez)
2121
- Add comment that `Number` is not a fully law abiding instance of `Ord` (#277 by @JamieBallingall)
22+
- The internal FFI function `join` in `Data.Show` has been renamed to `intercalate` to
23+
match the same function in `Data.Show.Generic` (#274 by @cdepillabout)
2224

2325
## [v5.0.1](https://github.com/purescript/purescript-prelude/releases/tag/v5.0.1) - 2021-05-11
2426

src/Data/Show.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const cons = function (head) {
6464
};
6565
};
6666

67-
export const join = function (separator) {
67+
export const intercalate = function (separator) {
6868
return function (xs) {
6969
return xs.join(separator);
7070
};

src/Data/Show.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ instance showProxy :: Show (Proxy a) where
4444
instance showRecord :: (RL.RowToList rs ls, ShowRecordFields ls rs) => Show (Record rs) where
4545
show record = case showRecordFields (Proxy :: Proxy ls) record of
4646
[] -> "{}"
47-
fields -> join " " [ "{", join ", " fields, "}" ]
47+
fields -> intercalate " " ["{", intercalate ", " fields, "}"]
4848

4949
-- | A class for records where all fields have `Show` instances, used to
5050
-- | implement the `Show` instance for records.
@@ -61,7 +61,7 @@ instance showRecordFieldsCons ::
6161
, Show focus
6262
) =>
6363
ShowRecordFields (RL.Cons key focus rowlistTail) row where
64-
showRecordFields _ record = cons (join ": " [ key, show focus ]) tail
64+
showRecordFields _ record = cons (intercalate ": " [ key, show focus ]) tail
6565
where
6666
key = reflectSymbol (Proxy :: Proxy key)
6767
focus = unsafeGet key record :: focus
@@ -73,4 +73,4 @@ foreign import showCharImpl :: Char -> String
7373
foreign import showStringImpl :: String -> String
7474
foreign import showArrayImpl :: forall a. (a -> String) -> Array a -> String
7575
foreign import cons :: forall a. a -> Array a -> Array a
76-
foreign import join :: String -> Array String -> String
76+
foreign import intercalate :: String -> Array String -> String

src/Data/Show/Generic.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
export const intercalate = function (separator) {
22
return function (xs) {
3-
var len = xs.length;
4-
if (len === 0) return "";
5-
6-
var res = xs[0];
7-
for (var i = 1; i < len; i++) {
8-
res = res + separator + xs[i];
9-
}
10-
return res;
3+
return xs.join(separator);
114
};
125
};

0 commit comments

Comments
 (0)