(n: number): (self: string) => string
(self: string, n: number): stringKeeps the specified number of characters from the start of a string.
Details
If n is larger than the available number of characters, the string will
be returned whole.
If n is not a positive number, an empty string will be returned.
If n is a float, it will be rounded down to the nearest integer.
Example (Taking characters from the start)
import { String } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(String.takeLeft("Hello World", 5), "Hello")export const const takeLeft: {
(n: number): (self: string) => string
(self: string, n: number): string
}
Keeps the specified number of characters from the start of a string.
Details
If n is larger than the available number of characters, the string will
be returned whole.
If n is not a positive number, an empty string will be returned.
If n is a float, it will be rounded down to the nearest integer.
Example (Taking characters from the start)
import { String } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(String.takeLeft("Hello World", 5), "Hello")
takeLeft: {
(n: numbern: number): (self: stringself: string) => string
(self: stringself: string, n: numbern: number): string
} = dual<(...args: Array<any>) => any, (self: string, n: number) => string>(arity: 2, body: (self: string, n: number) => string): ((...args: Array<any>) => any) & ((self: string, n: number) => string) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, (self: stringself: string, n: numbern: number): string => self: stringself.String.slice(start?: number, end?: number): stringReturns a section of a string.
slice(0, var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.max(...values: number[]): numberReturns the larger of a set of supplied numeric expressions.
max(n: numbern, 0)))