but currying didn't work well with pipe (since pipe is data-first), I had to do something like this:
import { pipe } from '@mobily/ts-belt'
type A = { tag: 'A' }
type B = { tag: 'B' }
type Two = A | B
function foo(a: Two): (c: Two) => Two
function foo(a: Two, b: Two): Two
function foo(a: Two, b?: Two) {
return b ? a : (c: Two) => foo(c, a)
}
const [a, b] = [{ tag: 'A' }, { tag: 'B' }] as const
console.log(foo(a, b)) // { tag: 'A' }
console.log(foo(b)(a)) // { tag: 'B' }
console.log(pipe(a, foo(b))) // { tag: 'A' }
is this considered idiomatic? I see most of ts-belt's (data-first) functions take the same approch, i.e reversed currying, for example S.concat:
function concat(appendValue: string): (str: string) => string
function concat(str: string, appendValue: string): string
however, I'm confused because ts-belt is written in rescript, and in rescript docs about pipe, it says
Do not abuse pipes; they're a means to an end. Inexperienced engineers sometimes shape a library's API to take advantage of the pipe. This is backwards.
does ts-belt take this approach because of pipe's limitation (cannot change position of argument unless using lambda)?
I was making interchangeable
Pos
andSize
, and they work likebut currying didn't work well with
pipe
(since pipe is data-first), I had to do something like this:is this considered idiomatic? I see most of
ts-belt
's (data-first) functions take the same approch, i.e reversed currying, for example S.concat:however, I'm confused because
ts-belt
is written in rescript, and in rescript docs about pipe, it saysdoes
ts-belt
take this approach because ofpipe
's limitation (cannot change position of argument unless using lambda)?