Hyperlinkv0.8.0-beta.28

String

String.splitconsteffect/String.ts:456
(separator: string | RegExp): (self: string) => NonEmptyArray<string>
(self: string, separator: string | RegExp): NonEmptyArray<string>

Splits a string into an array of substrings using a separator.

Example (Splitting strings)

import { pipe, String } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(pipe("abc", String.split("")), ["a", "b", "c"])
assert.deepStrictEqual(pipe("", String.split("")), [""])
assert.deepStrictEqual(String.split("hello,world", ","), ["hello", "world"])
transforming
Source effect/String.ts:4567 lines
export const split: {
  (separator: string | RegExp): (self: string) => NonEmptyArray<string>
  (self: string, separator: string | RegExp): NonEmptyArray<string>
} = dual(2, (self: string, separator: string | RegExp): NonEmptyArray<string> => {
  const out = self.split(separator)
  return readonlyArray.isArrayNonEmpty(out) ? out : [self]
})