<B extends string>(that: B): <A extends string>(self: A) => Concat<A, B>
<A extends string, B extends string>(self: A, that: B): Concat<A, B>Concatenates two strings at runtime.
Example (Concatenating strings)
import { pipe, String } from "effect"
const result1 = String.concat("hello", "world")
console.log(result1) // "helloworld"
const result2 = pipe("hello", String.concat("world"))
console.log(result2) // "helloworld"export const const concat: {
<B extends string>(that: B): <A extends string>(
self: A
) => Concat<A, B>
<A extends string, B extends string>(
self: A,
that: B
): Concat<A, B>
}
Concatenates two strings at runtime.
Example (Concatenating strings)
import { pipe, String } from "effect"
const result1 = String.concat("hello", "world")
console.log(result1) // "helloworld"
const result2 = pipe("hello", String.concat("world"))
console.log(result2) // "helloworld"
concat: {
<function (type parameter) B in <B extends string>(that: B): <A extends string>(self: A) => Concat<A, B>B extends string>(that: B extends stringthat: function (type parameter) B in <B extends string>(that: B): <A extends string>(self: A) => Concat<A, B>B): <function (type parameter) A in <A extends string>(self: A): Concat<A, B>A extends string>(self: A extends stringself: function (type parameter) A in <A extends string>(self: A): Concat<A, B>A) => type Concat<
A extends string,
B extends string
> = `${A}${B}`
Concatenates two strings at the type level.
Example (Concatenating string literal types)
import type { String } from "effect"
// Type-level concatenation
type Result = String.Concat<"hello", "world"> // "helloworld"
Concat<function (type parameter) A in <A extends string>(self: A): Concat<A, B>A, function (type parameter) B in <B extends string>(that: B): <A extends string>(self: A) => Concat<A, B>B>
<function (type parameter) A in <A extends string, B extends string>(self: A, that: B): Concat<A, B>A extends string, function (type parameter) B in <A extends string, B extends string>(self: A, that: B): Concat<A, B>B extends string>(self: A extends stringself: function (type parameter) A in <A extends string, B extends string>(self: A, that: B): Concat<A, B>A, that: B extends stringthat: function (type parameter) B in <A extends string, B extends string>(self: A, that: B): Concat<A, B>B): type Concat<
A extends string,
B extends string
> = `${A}${B}`
Concatenates two strings at the type level.
Example (Concatenating string literal types)
import type { String } from "effect"
// Type-level concatenation
type Result = String.Concat<"hello", "world"> // "helloworld"
Concat<function (type parameter) A in <A extends string, B extends string>(self: A, that: B): Concat<A, B>A, function (type parameter) B in <A extends string, B extends string>(self: A, that: B): Concat<A, B>B>
} = dual<(...args: Array<any>) => any, (self: string, that: string) => string>(arity: 2, body: (self: string, that: string) => string): ((...args: Array<any>) => any) & ((self: string, that: string) => 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, that: stringthat: string): string => self: stringself + that: stringthat)