fp-tsの一覧ページがあまりにも重くなったので、分割
参照元
一覧
そこそこ参照されているもの一覧
ファイル名 | import先 | ソースの中身 | declare module がある | importでの参照される数 |
---|---|---|---|---|
Chain |
|
interface, function のみ | なし | 6 |
Either | たくさん | いろいろ | URItoKind2<E, A> | 6 |
Eq |
|
いろいろ | URItoKind<A> | 6 |
internal | いくつか | interface, type, const のみ | なし | 6 |
Applicative |
|
interface, function のみ | なし | 5 |
Contravariant |
|
interface のみ | なし | 5 |
IO | たくさん | いろいろ | URItoKind<A> | 5 |
Monad |
|
interface のみ | なし | 5 |
Ord |
|
いろいろ | URItoKind<A> | 5 |
ReadonlyRecord | たくさん | いろいろ | URItoKind<A> | 5 |
Chainの内容確認
参考
import { describe, it } from 'vitest'
import * as C from 'fp-ts/Chain'
import { pipe } from 'fp-ts/lib/function'
import type { Kind, URIS } from 'fp-ts/lib/HKT'
import type { Chain1 } from 'fp-ts/Chain'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
const TestChain1Test2: Chain1<URI> = {
URI,
chain: (fa, f) => f(fa.Test2),
ap: (fab, fa) => ({ Test2: fab.Test2(fa.Test2) }),
map: (fa, f) => ({ Test2: f(fa.Test2) })
}
function liftChain<F extends URIS>(
F: Chain1<F>
): <A, B>(f: (a: A) => Kind<F, B>) => (fa: Kind<F, A>) => Kind<F, B> {
return (f) => (fa) => F.chain(fa, f)
}
function liftAp<F extends URIS>(
F: Chain1<F>
): <A, B>(fab: Kind<F, (a: A) => B>) => (fa: Kind<F, A>) => Kind<F, B> {
return (fab) => (fa) => F.ap(fab, fa)
}
function liftMap<F extends URIS>(
F: Chain1<F>
): <A, B>(f: (a: A) => B) => (fa: Kind<F, A>) => Kind<F, B> {
return (f) => (fa) => F.map(fa, f)
}
type Test2<A> = {
Test2: A
}
type _a = number
type _b = string
type A = Test2<_a>
type B = Test2<_b>
describe('fp-ts Tutorial', () => {
it('Chain', () => {
// base
const a1: A = { Test2: 123 }
// _a function
const _a_a_function_double: (a: _a) => _a = (a) => a * 2
const _a_b_function: (a: _a) => _b = (a) => String(a)
const _a_A_function_double: (a: _a) => A = (a) => ({
Test2: _a_a_function_double(a)
})
const _a_B_function: (a: _a) => B = (a) => ({
Test2: _a_b_function(a)
})
// function object
const a_b_function_object: Test2<(a: _a) => _b> = {
Test2: _a_b_function
}
const a_a_function_object: Test2<(a: _a) => _a> = {
Test2: _a_a_function_double
}
// test
console.log(
'liftChain TestChain1Test2 - ',
pipe(a1, liftChain(TestChain1Test2)(_a_A_function_double))
)
console.log('liftChain TestChain1Test2 - ', pipe(a1, liftChain(TestChain1Test2)(_a_B_function)))
console.log('liftAp TestChain1Test2 - ', pipe(a1, liftAp(TestChain1Test2)(a_a_function_object)))
console.log('liftAp TestChain1Test2 - ', pipe(a1, liftAp(TestChain1Test2)(a_b_function_object)))
console.log(
'liftMap TestChain1Test2 - ',
pipe(a1, liftMap(TestChain1Test2)(_a_a_function_double))
)
console.log('liftMap TestChain1Test2 - ', pipe(a1, liftMap(TestChain1Test2)(_a_b_function)))
console.log('---------')
console.log(
'chainFirst - _a_A_function_double - ',
pipe(a1, C.chainFirst(TestChain1Test2)(_a_A_function_double))
)
console.log(
'chainFirst - _a_B_function - ',
pipe(a1, C.chainFirst(TestChain1Test2)(_a_B_function))
)
console.log('---------')
console.log(
'bind - _a_A_function_double - ',
pipe(a1, C.bind(TestChain1Test2)('bind target name', _a_A_function_double))
)
console.log(
'bind - _a_B_function - ',
pipe(a1, C.bind(TestChain1Test2)('bind target name', _a_B_function))
)
})
})
実行結果
liftChain TestChain1Test2 - { Test2: 246 }
liftChain TestChain1Test2 - { Test2: '123' }
liftAp TestChain1Test2 - { Test2: 246 }
liftAp TestChain1Test2 - { Test2: '123' }
liftMap TestChain1Test2 - { Test2: 246 }
liftMap TestChain1Test2 - { Test2: '123' }
---------
chainFirst - _a_A_function_double - { Test2: 123 }
chainFirst - _a_B_function - { Test2: 123 }
---------
bind - _a_A_function_double - { Test2: { 'bind target name': 246 } }
bind - _a_B_function - { Test2: { 'bind target name': '123' } }
Eitherの内容確認
参考
import { describe, it } from 'vitest'
import * as E from 'fp-ts/Either'
import * as O from 'fp-ts/Option'
import { pipe } from 'fp-ts/lib/function'
import type { Either } from 'fp-ts/Either'
import type { Show } from 'fp-ts/lib/Show'
import type { Eq } from 'fp-ts/lib/Eq'
import type { Semigroup } from 'fp-ts/lib/Semigroup'
import type { Monoid } from 'fp-ts/lib/Monoid'
import type { Option } from 'fp-ts/lib/Option'
import type { Applicative1 } from 'fp-ts/lib/Applicative'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
const TestApplicative1Test2: Applicative1<URI> = {
URI,
ap: (fab, fa) => ({ Test2: fab.Test2(fa.Test2) }),
of: <XXX>(a: XXX) => ({ Test2: a }),
map: (fa, f) => ({ Test2: f(fa.Test2) })
}
type Test2<XXX> = {
Test2: XXX
}
interface Test23<XXX> extends Test2<XXX> {
Test23: `extends Test2<${XXX extends string ? XXX : XXX extends number ? XXX : 'something'}>`
}
type _a = number
type _b = string
type A = Test2<_a>
type B = Test2<_b>
type A_extends = Test23<_a>
// type OA = Option<A>
type OB = Option<B>
type swap_OA = Test2<Option<_a>>
type ErrorType = string[]
type FA = Either<ErrorType, A>
type FA_extends = Either<ErrorType, A_extends>
type swap_FA = Test2<Either<ErrorType, _a>>
type FOA = Either<ErrorType, Option<A>>
type FFA = Either<ErrorType, FA>
type F_A_B = Either<ErrorType, (a: A) => B>
const TestShowErrorType: Show<ErrorType> = {
show: (error) => pipe(error, JSON.stringify)
}
const TestShowTest2a: Show<A> = {
show: (a) => pipe(a, JSON.stringify)
}
const TestEqErrorType: Eq<ErrorType> = {
equals: (x, y) => JSON.stringify(x) === JSON.stringify(y)
}
const TestEqTest2a: Eq<A> = {
equals: (x, y) => x.Test2 === y.Test2
}
const TestSemigroupErrorType: Semigroup<ErrorType> = {
concat: (x, y) => x.concat(y)
}
const TestSemigroupTest2a: Semigroup<A> = {
concat: (x, y) => ({ Test2: x.Test2 + y.Test2 })
}
const TestMonoidErrorType: Monoid<ErrorType> = {
concat: TestSemigroupErrorType.concat,
empty: ['']
}
const TestMonoidTest2b: Monoid<B> = {
concat: (x, y) => ({ Test2: `${x.Test2} - ${y.Test2}` }),
empty: { Test2: '' }
}
describe('fp-ts Tutorial', () => {
it('Either', () => {
// base
const _a1: _a = 123
const _a2: _a = 456
const _b1: _b = 'abc'
const a1: A = { Test2: _a1 }
const a2: A = { Test2: _a2 }
const a1_extends: A_extends = { Test2: _a1, Test23: 'extends Test2<123>' }
const b1: B = { Test2: _b1 }
const e1: ErrorType = ['error fa1l']
const faLeft: FA = E.left(e1)
const fa1Right: FA = E.right(a1)
const fa2Right: FA = E.right(a2)
const faLeft_extends: FA_extends = E.left(e1)
const fa1Right_extends: FA_extends = E.right(a1_extends)
const foaLeft: FOA = E.left(e1)
const foaRightNone: FOA = E.right(O.none)
const foa1RightSome: FOA = E.right(O.some(a1))
const ffaLeft: FFA = E.left(e1)
const ffa1RightLeft: FFA = E.right(E.left(e1))
const ffa1RightRight: FFA = E.right(E.right(a1))
// refinement, predicate
const a_is_A_extends_refinement = (a: A): a is A_extends => 'Test23' in a
// const ia_refinement_A_extends = <I>(i: I, a: A): a is A_extends => a_is_A_extends_refinement(a)
const a_is_bool_predicate = (a: A): boolean => a.Test2 % 2 === 1
// const ia_predicate_a_is_bool = <I>(i: I, a: A): boolean => a_is_bool_predicate(a)
// a functoin
const a_b_function: (a: A) => B = (a) => ({
Test2: `${a.Test2}`
})
const A_FA_function_even_is_ok: (a: A) => FA = (a) =>
a.Test2 % 2 === 0 ? E.right(a) : E.left([String(a.Test2), '<= odd number is ng'])
const a_OB_function_even_is_ok: (a: A) => OB = (a) =>
a.Test2 % 2 === 0 ? O.some(a_b_function(a)) : O.none
const A_swap_FA_function_even_is_ok: (a: A) => swap_FA = (a) => ({
Test2: a.Test2 % 2 === 0 ? E.right(a.Test2) : E.left([String(a.Test2), '<= odd number is ng'])
})
const A_swap_OA_function_even_is_ok: (a: A) => swap_OA = (a) => ({
Test2: a.Test2 % 2 === 0 ? O.some(a.Test2) : O.none
})
// ab function
const ba_b_function: (b: B, a: A) => B = (b, a) => ({
Test2: `${b.Test2} :: ${a_b_function(a).Test2}`
})
const ab_b_function: (a: A, b: B) => B = (a, b) => ba_b_function(b, a)
// function object
const f_a_bLeft: F_A_B = E.left(e1)
const f_a_bRight: F_A_B = E.right(a_b_function)
// test
console.log('a1 - ', a1)
console.log('a2 - ', a2)
console.log('e1 - ', e1)
console.log('faLeft - ', faLeft)
console.log('fa1Right - ', fa1Right)
console.log('foaLeft - ', foaLeft)
console.log('foaRightNone - ', foaRightNone)
console.log('foa1RightSome - ', foa1RightSome)
console.log('ffaLeft - ', ffaLeft)
console.log('ffa1RightLeft - ', ffa1RightLeft)
console.log('ffa1RightRight - ', ffa1RightRight)
console.log('---------')
console.log('f_a_bLeft - ', f_a_bLeft)
console.log('f_a_bRight - ', f_a_bRight)
console.log('---------')
console.log(
'flatMap - faLeft - ',
pipe(faLeft, E.flatMap<A, ErrorType, A>(A_FA_function_even_is_ok))
)
console.log(
'flatMap - fa1Right - ',
pipe(fa1Right, E.flatMap<A, ErrorType, A>(A_FA_function_even_is_ok))
)
console.log(
'flatMap - fa2Right - ',
pipe(fa2Right, E.flatMap<A, ErrorType, A>(A_FA_function_even_is_ok))
)
console.log('---------')
console.log(
'getShow - show - faLeft - ',
pipe(faLeft, E.getShow(TestShowErrorType, TestShowTest2a).show)
)
console.log(
'getShow - show - fa1Right - ',
pipe(fa1Right, E.getShow(TestShowErrorType, TestShowTest2a).show)
)
console.log(
'getShow - show - fa2Right - ',
pipe(fa2Right, E.getShow(TestShowErrorType, TestShowTest2a).show)
)
console.log('---------')
console.log(
'getEq - equals - (faLeft, fa1Right) - ',
E.getEq(TestEqErrorType, TestEqTest2a).equals(faLeft, fa1Right)
)
console.log(
'getEq - equals - (faLeft, faLeft) - ',
E.getEq(TestEqErrorType, TestEqTest2a).equals(faLeft, faLeft)
)
console.log(
'getEq - equals - (fa1Right, fa1Right) - ',
E.getEq(TestEqErrorType, TestEqTest2a).equals(fa1Right, fa1Right)
)
console.log(
'getEq - equals - (fa1Right, fa2Right) - ',
E.getEq(TestEqErrorType, TestEqTest2a).equals(fa1Right, fa2Right)
)
console.log('---------')
console.log(
'getSemigroup - concat - (faLeft, fa1Right) - ',
E.getSemigroup(TestSemigroupTest2a).concat(faLeft, fa1Right)
)
console.log(
'getSemigroup - concat - (fa1Right, fa2Right) - [579 => 123 + 456] - ',
E.getSemigroup(TestSemigroupTest2a).concat(fa1Right, fa2Right)
)
console.log('---------')
console.log(
'getCompactable - compact - foaLeft - ',
pipe(foaLeft, E.getCompactable(TestMonoidErrorType).compact)
)
console.log(
'getCompactable - compact - foaRightNone - ',
pipe(foaRightNone, E.getCompactable(TestMonoidErrorType).compact)
)
console.log(
'getCompactable - compact - foa1RightSome - ',
pipe(foa1RightSome, E.getCompactable(TestMonoidErrorType).compact)
)
console.log(
'getCompactable - separate - ffaLeft - ',
pipe(ffaLeft, E.getCompactable(TestMonoidErrorType).separate)
)
console.log(
'getCompactable - separate - ffa1RightLeft - ',
pipe(ffa1RightLeft, E.getCompactable(TestMonoidErrorType).separate)
)
console.log(
'getCompactable - separate - ffa1RightRight - ',
pipe(ffa1RightRight, E.getCompactable(TestMonoidErrorType).separate)
)
console.log('---------')
console.log(
'getFilterable - compact - foaLeft - ',
pipe(foaLeft, E.getFilterable(TestMonoidErrorType).compact)
)
console.log(
'getFilterable - compact - foaRightNone - ',
pipe(foaRightNone, E.getFilterable(TestMonoidErrorType).compact)
)
console.log(
'getFilterable - compact - foa1RightSome - ',
pipe(foa1RightSome, E.getFilterable(TestMonoidErrorType).compact)
)
console.log(
'getFilterable - filter - faLeft - ',
E.getFilterable(TestMonoidErrorType).filter(faLeft, a_is_A_extends_refinement)
)
console.log(
'getFilterable - filter - faLeft_extends - ',
E.getFilterable(TestMonoidErrorType).filter(faLeft_extends, a_is_A_extends_refinement)
)
console.log(
'getFilterable - filter - fa1Right - ',
E.getFilterable(TestMonoidErrorType).filter(fa1Right, a_is_A_extends_refinement)
)
console.log(
'getFilterable - filter - fa1Right_extends - ',
E.getFilterable(TestMonoidErrorType).filter(fa1Right_extends, a_is_A_extends_refinement)
)
console.log(
'getFilterable - filter - faLeft - ',
E.getFilterable(TestMonoidErrorType).filterMap<A, B>(faLeft, a_OB_function_even_is_ok)
)
console.log(
'getFilterable - filter - fa1Right - ',
E.getFilterable(TestMonoidErrorType).filterMap<A, B>(fa1Right, a_OB_function_even_is_ok)
)
console.log(
'getFilterable - filter - fa2Right - ',
E.getFilterable(TestMonoidErrorType).filterMap<A, B>(fa2Right, a_OB_function_even_is_ok)
)
console.log(
'getFilterable - map - faLeft - ',
E.getFilterable(TestMonoidErrorType).map<A, B>(faLeft, a_b_function)
)
console.log(
'getFilterable - map - fa1Right - ',
E.getFilterable(TestMonoidErrorType).map<A, B>(fa1Right, a_b_function)
)
console.log(
'getFilterable - map - fa2Right - ',
E.getFilterable(TestMonoidErrorType).map<A, B>(fa2Right, a_b_function)
)
console.log(
'getFilterable - partition - faLeft - a_is_A_extends_refinement - ',
E.getFilterable(TestMonoidErrorType).partition(faLeft, a_is_A_extends_refinement)
)
console.log(
'getFilterable - partition - faLeft_extends - a_is_A_extends_refinement - ',
E.getFilterable(TestMonoidErrorType).partition(faLeft_extends, a_is_A_extends_refinement)
)
console.log(
'getFilterable - partition - fa1Right - a_is_A_extends_refinement - ',
E.getFilterable(TestMonoidErrorType).partition(fa1Right, a_is_A_extends_refinement)
)
console.log(
'getFilterable - partition - fa1Right_extends - a_is_A_extends_refinement - ',
E.getFilterable(TestMonoidErrorType).partition(fa1Right_extends, a_is_A_extends_refinement)
)
console.log(
'getFilterable - partition - faLeft - a_is_bool_predicate - ',
E.getFilterable(TestMonoidErrorType).partition(faLeft, a_is_bool_predicate)
)
console.log(
'getFilterable - partition - fa1Right - a_is_bool_predicate - ',
E.getFilterable(TestMonoidErrorType).partition(fa1Right, a_is_bool_predicate)
)
console.log(
'getFilterable - partition - fa2Right - a_is_bool_predicate - ',
E.getFilterable(TestMonoidErrorType).partition(fa2Right, a_is_bool_predicate)
)
console.log(
'getFilterable - partitionMap - faLeft - ',
E.getFilterable(TestMonoidErrorType).partitionMap(faLeft, A_FA_function_even_is_ok)
)
console.log(
'getFilterable - partitionMap - fa1Right - ',
E.getFilterable(TestMonoidErrorType).partitionMap(fa1Right, A_FA_function_even_is_ok)
)
console.log(
'getFilterable - partitionMap - fa2Right - ',
E.getFilterable(TestMonoidErrorType).partitionMap(fa2Right, A_FA_function_even_is_ok)
)
console.log(
'getFilterable - separate - ffaLeft - ',
pipe(ffaLeft, E.getFilterable(TestMonoidErrorType).separate)
)
console.log(
'getFilterable - separate - ffa1RightLeft - ',
pipe(ffa1RightLeft, E.getFilterable(TestMonoidErrorType).separate)
)
console.log(
'getFilterable - separate - ffa1RightRight - ',
pipe(ffa1RightRight, E.getFilterable(TestMonoidErrorType).separate)
)
console.log('---------')
console.log(
'getWitherable - compact - foaLeft - ',
pipe(foaLeft, E.getWitherable(TestMonoidErrorType).compact)
)
console.log(
'getWitherable - compact - foaRightNone - ',
pipe(foaRightNone, E.getWitherable(TestMonoidErrorType).compact)
)
console.log(
'getWitherable - compact - foa1RightSome - ',
pipe(foa1RightSome, E.getWitherable(TestMonoidErrorType).compact)
)
console.log(
'getWitherable - filter - faLeft - ',
E.getWitherable(TestMonoidErrorType).filter(faLeft, a_is_A_extends_refinement)
)
console.log(
'getWitherable - filter - faLeft_extends - ',
E.getWitherable(TestMonoidErrorType).filter(faLeft_extends, a_is_A_extends_refinement)
)
console.log(
'getWitherable - filter - fa1Right - ',
E.getWitherable(TestMonoidErrorType).filter(fa1Right, a_is_A_extends_refinement)
)
console.log(
'getWitherable - filter - fa1right_extends - ',
E.getWitherable(TestMonoidErrorType).filter(fa1Right_extends, a_is_A_extends_refinement)
)
console.log(
'getWitherable - filter - faLeft - ',
E.getWitherable(TestMonoidErrorType).filterMap<A, B>(faLeft, a_OB_function_even_is_ok)
)
console.log(
'getWitherable - filter - fa1Right - ',
E.getWitherable(TestMonoidErrorType).filterMap<A, B>(fa1Right, a_OB_function_even_is_ok)
)
console.log(
'getWitherable - filter - fa2Right - ',
E.getWitherable(TestMonoidErrorType).filterMap<A, B>(fa2Right, a_OB_function_even_is_ok)
)
console.log(
'getWitherable - foldMap - faLeft - ',
E.getWitherable(TestMonoidErrorType).foldMap(TestMonoidTest2b)(faLeft, a_b_function)
)
console.log(
'getWitherable - foldMap - fa1Right - ',
E.getWitherable(TestMonoidErrorType).foldMap(TestMonoidTest2b)(fa1Right, a_b_function)
)
console.log(
'getWitherable - foldMap - fa2Right - ',
E.getWitherable(TestMonoidErrorType).foldMap(TestMonoidTest2b)(fa2Right, a_b_function)
)
console.log(
'getWitherable - map - faLeft - ',
E.getWitherable(TestMonoidErrorType).map<A, B>(faLeft, a_b_function)
)
console.log(
'getWitherable - map - fa1Right - ',
E.getWitherable(TestMonoidErrorType).map<A, B>(fa1Right, a_b_function)
)
console.log(
'getWitherable - map - fa2Right - ',
E.getWitherable(TestMonoidErrorType).map<A, B>(fa2Right, a_b_function)
)
console.log(
'getWitherable - partition - faLeft - a_is_A_extends_refinement - ',
E.getWitherable(TestMonoidErrorType).partition(faLeft, a_is_A_extends_refinement)
)
console.log(
'getWitherable - partition - faLeft_extends - a_is_A_extends_refinement - ',
E.getWitherable(TestMonoidErrorType).partition(faLeft_extends, a_is_A_extends_refinement)
)
console.log(
'getWitherable - partition - fa1Right - a_is_A_extends_refinement - ',
E.getWitherable(TestMonoidErrorType).partition(fa1Right, a_is_A_extends_refinement)
)
console.log(
'getWitherable - partition - fa1Right_extends - a_is_A_extends_refinement - ',
E.getWitherable(TestMonoidErrorType).partition(fa1Right_extends, a_is_A_extends_refinement)
)
console.log(
'getWitherable - partition - faLeft - a_is_bool_predicate - ',
E.getWitherable(TestMonoidErrorType).partition(faLeft, a_is_bool_predicate)
)
console.log(
'getWitherable - partition - fa1Right - a_is_bool_predicate - ',
E.getWitherable(TestMonoidErrorType).partition(fa1Right, a_is_bool_predicate)
)
console.log(
'getWitherable - partition - fa2Right - a_is_bool_predicate - ',
E.getWitherable(TestMonoidErrorType).partition(fa2Right, a_is_bool_predicate)
)
console.log(
'getWitherable - partitionMap - faLeft - ',
E.getWitherable(TestMonoidErrorType).partitionMap(faLeft, A_FA_function_even_is_ok)
)
console.log(
'getWitherable - partitionMap - fa1Right - ',
E.getWitherable(TestMonoidErrorType).partitionMap(fa1Right, A_FA_function_even_is_ok)
)
console.log(
'getWitherable - partitionMap - fa2Right - ',
E.getWitherable(TestMonoidErrorType).partitionMap(fa2Right, A_FA_function_even_is_ok)
)
console.log(
'getWitherable - reduce - faLeft - b1 - ',
E.getWitherable(TestMonoidErrorType).reduce(faLeft, b1, ba_b_function)
)
console.log(
'getWitherable - reduce - fa1Right - b1 - ',
E.getWitherable(TestMonoidErrorType).reduce(fa1Right, b1, ba_b_function)
)
console.log(
'getWitherable - reduce - fa2Right - b1 - ',
E.getWitherable(TestMonoidErrorType).reduce(fa2Right, b1, ba_b_function)
)
console.log(
'getWitherable - reduceRight - faLeft - b1 - ',
E.getWitherable(TestMonoidErrorType).reduceRight(faLeft, b1, ab_b_function)
)
console.log(
'getWitherable - reduceRight - fa1Right - b1 - ',
E.getWitherable(TestMonoidErrorType).reduceRight(fa1Right, b1, ab_b_function)
)
console.log(
'getWitherable - reduceRight - fa2Right - b1 - ',
E.getWitherable(TestMonoidErrorType).reduceRight(fa2Right, b1, ab_b_function)
)
console.log(
'getWitherable - separate - ffaLeft - ',
pipe(ffaLeft, E.getWitherable(TestMonoidErrorType).separate)
)
console.log(
'getWitherable - separate - ffa1RightLeft - ',
pipe(ffa1RightLeft, E.getWitherable(TestMonoidErrorType).separate)
)
console.log(
'getWitherable - separate - ffa1RightRight - ',
pipe(ffa1RightRight, E.getWitherable(TestMonoidErrorType).separate)
)
console.log(
'getWitherable - sequence - faLeft - ',
pipe(faLeft, E.getWitherable(TestMonoidErrorType).sequence(TestApplicative1Test2))
)
console.log(
'getWitherable - sequence - fa1Right - ',
pipe(fa1Right, E.getWitherable(TestMonoidErrorType).sequence(TestApplicative1Test2))
)
console.log(
'getWitherable - sequence - fa2Right - ',
pipe(fa2Right, E.getWitherable(TestMonoidErrorType).sequence(TestApplicative1Test2))
)
console.log(
'getWitherable - traverse - faLeft - ',
E.getWitherable(TestMonoidErrorType).traverse(TestApplicative1Test2)(faLeft, a_b_function)
)
console.log(
'getWitherable - traverse - fa1Right - ',
E.getWitherable(TestMonoidErrorType).traverse(TestApplicative1Test2)(fa1Right, a_b_function)
)
console.log(
'getWitherable - traverse - fa2Right - ',
E.getWitherable(TestMonoidErrorType).traverse(TestApplicative1Test2)(fa2Right, a_b_function)
)
console.log(
'getWitherable - wilt - faLeft - ',
E.getWitherable(TestMonoidErrorType).wilt(TestApplicative1Test2)(
faLeft,
A_swap_FA_function_even_is_ok
)
)
console.log(
'getWitherable - wilt - fa1Right - ',
E.getWitherable(TestMonoidErrorType).wilt(TestApplicative1Test2)(
fa1Right,
A_swap_FA_function_even_is_ok
)
)
console.log(
'getWitherable - wilt - fa2Right - ',
E.getWitherable(TestMonoidErrorType).wilt(TestApplicative1Test2)(
fa2Right,
A_swap_FA_function_even_is_ok
)
)
console.log(
'getWitherable - wither - faLeft - ',
E.getWitherable(TestMonoidErrorType).wither(TestApplicative1Test2)(
faLeft,
A_swap_OA_function_even_is_ok
)
)
console.log(
'getWitherable - wither - fa1Right - ',
E.getWitherable(TestMonoidErrorType).wither(TestApplicative1Test2)(
fa1Right,
A_swap_OA_function_even_is_ok
)
)
console.log(
'getWitherable - wither - fa2Right - ',
E.getWitherable(TestMonoidErrorType).wither(TestApplicative1Test2)(
fa2Right,
A_swap_OA_function_even_is_ok
)
)
console.log('---------')
console.log(
'getApplicativeValidation - ap - faLeft - f_a_bLeft - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bLeft, faLeft)
)
console.log(
'getApplicativeValidation - ap - fa1Right - f_a_bLeft - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bLeft, fa1Right)
)
console.log(
'getApplicativeValidation - ap - fa2Right - f_a_bLeft - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bLeft, fa2Right)
)
console.log(
'getApplicativeValidation - ap - faLeft - f_a_bRight - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bRight, faLeft)
)
console.log(
'getApplicativeValidation - ap - fa1Right - f_a_bRight - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bRight, fa1Right)
)
console.log(
'getApplicativeValidation - ap - fa2Right - f_a_bRight - ',
E.getApplicativeValidation(TestSemigroupErrorType).ap(f_a_bRight, fa2Right)
)
console.log(
'getApplicativeValidation - ap - faLeft - ',
E.getApplicativeValidation(TestSemigroupErrorType).map(faLeft, a_b_function)
)
console.log(
'getApplicativeValidation - ap - fa1Right - ',
E.getApplicativeValidation(TestSemigroupErrorType).map(fa1Right, a_b_function)
)
console.log(
'getApplicativeValidation - ap - fa2Right - ',
E.getApplicativeValidation(TestSemigroupErrorType).map(fa2Right, a_b_function)
)
console.log(
'getApplicativeValidation - of - faLeft - ',
E.getApplicativeValidation(TestSemigroupErrorType).of(faLeft)
)
console.log(
'getApplicativeValidation - of - fa1Right - ',
E.getApplicativeValidation(TestSemigroupErrorType).of(fa1Right)
)
console.log(
'getApplicativeValidation - of - fa2Right - ',
E.getApplicativeValidation(TestSemigroupErrorType).of(fa2Right)
)
console.log(
'getAltValidation - alt - faLeft - faLeft',
E.getAltValidation(TestSemigroupErrorType).alt(faLeft, () => faLeft)
)
console.log(
'getAltValidation - alt - faLeft - fa1Right',
E.getAltValidation(TestSemigroupErrorType).alt(faLeft, () => fa1Right)
)
console.log(
'getAltValidation - alt - fa1Right - faLeft',
E.getAltValidation(TestSemigroupErrorType).alt(fa1Right, () => faLeft)
)
console.log(
'getAltValidation - alt - fa1Right - fa2Right',
E.getAltValidation(TestSemigroupErrorType).alt(fa1Right, () => fa2Right)
)
console.log(
'getAltValidation - map - faLeft - ',
E.getAltValidation(TestSemigroupErrorType).map(faLeft, a_b_function)
)
console.log(
'getAltValidation - map - fa1Right - ',
E.getAltValidation(TestSemigroupErrorType).map(fa1Right, a_b_function)
)
console.log(
'getAltValidation - map - fa2Right - ',
E.getAltValidation(TestSemigroupErrorType).map(fa2Right, a_b_function)
)
console.log('---------')
console.log('map - faLeft - ', pipe(faLeft, E.map(a_b_function)))
console.log('map - fa1Right - ', pipe(fa1Right, E.map(a_b_function)))
console.log('map - fa2Right - ', pipe(fa2Right, E.map(a_b_function)))
console.log('---------')
console.log('Functor - map - faLeft - ', E.Functor.map(faLeft, a_b_function))
console.log('Functor - map - fa1Right - ', E.Functor.map(fa1Right, a_b_function))
console.log('Functor - map - fa2Right - ', E.Functor.map(fa2Right, a_b_function))
console.log('---------')
console.log('as - (faLeft, faLeft) - ', E.as(faLeft, faLeft))
console.log('as - (faLeft, fa1Right) - ', E.as(faLeft, fa1Right))
console.log('as - (fa1Right, faLeft) - ', E.as(fa1Right, faLeft))
console.log('as - (fa1Right, fa2Right) - ', E.as(fa1Right, fa2Right))
console.log('as - (fa1Right, fa2Right) - ', pipe(fa1Right, E.as(fa2Right)))
console.log('---------')
console.log('asUnit - faLeft - ', E.asUnit(faLeft))
console.log('asUnit - fa1Right - ', E.asUnit(fa1Right))
console.log('---------')
console.log('of - _a1 - ', E.of(_a1))
console.log('of - faLeft - ', E.of(faLeft))
console.log('of - fa1Right - ', E.of(fa1Right))
console.log('---------')
console.log('Pointed - of - _a1 - ', E.Pointed.of(_a1))
console.log('Pointed - of - faLeft - ', E.Pointed.of(faLeft))
console.log('Pointed - of - fa1Right - ', E.Pointed.of(fa1Right))
console.log('---------')
console.log('apW - faLeft - f_a_bLeft - ', pipe(f_a_bLeft, E.apW(faLeft)))
console.log('apW - fa1Right - f_a_bLeft - ', pipe(f_a_bLeft, E.apW(fa1Right)))
console.log('apW - faLeft - f_a_bRight - ', pipe(f_a_bRight, E.apW(faLeft)))
console.log('apW - fa1Right - f_a_bRight - ', pipe(f_a_bRight, E.apW(fa1Right)))
})
})
実行結果
a1 - { Test2: 123 }
a2 - { Test2: 456 }
e1 - [ 'error fa1l' ]
faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
fa1Right - { _tag: 'Right', right: { Test2: 123 } }
foaLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
foaRightNone - { _tag: 'Right', right: { _tag: 'None' } }
foa1RightSome - { _tag: 'Right', right: { _tag: 'Some', value: { Test2: 123 } } }
ffaLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
ffa1RightLeft - { _tag: 'Right', right: { _tag: 'Left', left: [ 'error fa1l' ] } }
ffa1RightRight - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 123 } } }
---------
f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
f_a_bRight - { _tag: 'Right', right: [Function: a_b_function] }
---------
flatMap - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
flatMap - fa1Right - { _tag: 'Left', left: [ '123', '<= odd number is ng' ] }
flatMap - fa2Right - { _tag: 'Right', right: { Test2: 456 } }
---------
getShow - show - faLeft - left(["error fa1l"])
getShow - show - fa1Right - right({"Test2":123})
getShow - show - fa2Right - right({"Test2":456})
---------
getEq - equals - (faLeft, fa1Right) - false
getEq - equals - (faLeft, faLeft) - true
getEq - equals - (fa1Right, fa1Right) - true
getEq - equals - (fa1Right, fa2Right) - false
---------
getSemigroup - concat - (faLeft, fa1Right) - { _tag: 'Right', right: { Test2: 123 } }
getSemigroup - concat - (fa1Right, fa2Right) - [579 => 123 + 456] - { _tag: 'Right', right: { Test2: 579 } }
---------
getCompactable - compact - foaLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getCompactable - compact - foaRightNone - { _tag: 'Left', left: [ '' ] }
getCompactable - compact - foa1RightSome - { _tag: 'Right', right: { Test2: 123 } }
getCompactable - separate - ffaLeft - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getCompactable - separate - ffa1RightLeft - {
left: { _tag: 'Right', right: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ '' ] }
}
getCompactable - separate - ffa1RightRight - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 123 } }
}
---------
getFilterable - compact - foaLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getFilterable - compact - foaRightNone - { _tag: 'Left', left: [ '' ] }
getFilterable - compact - foa1RightSome - { _tag: 'Right', right: { Test2: 123 } }
getFilterable - filter - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getFilterable - filter - faLeft_extends - { _tag: 'Left', left: [ 'error fa1l' ] }
getFilterable - filter - fa1Right - { _tag: 'Left', left: [ '' ] }
getFilterable - filter - fa1Right_extends - { _tag: 'Right', right: { Test2: 123, Test23: 'extends Test2<123>' } }
getFilterable - filter - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getFilterable - filter - fa1Right - { _tag: 'Left', left: [ '' ] }
getFilterable - filter - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
getFilterable - map - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getFilterable - map - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
getFilterable - map - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
getFilterable - partition - faLeft - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getFilterable - partition - faLeft_extends - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getFilterable - partition - fa1Right - a_is_A_extends_refinement - {
left: { _tag: 'Right', right: { Test2: 123 } },
right: { _tag: 'Left', left: [ '' ] }
}
getFilterable - partition - fa1Right_extends - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ '' ] },
right: {
_tag: 'Right',
right: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
getFilterable - partition - faLeft - a_is_bool_predicate - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getFilterable - partition - fa1Right - a_is_bool_predicate - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 123 } }
}
getFilterable - partition - fa2Right - a_is_bool_predicate - {
left: { _tag: 'Right', right: { Test2: 456 } },
right: { _tag: 'Left', left: [ '' ] }
}
getFilterable - partitionMap - faLeft - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getFilterable - partitionMap - fa1Right - {
left: { _tag: 'Right', right: [ '123', '<= odd number is ng' ] },
right: { _tag: 'Left', left: [ '' ] }
}
getFilterable - partitionMap - fa2Right - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 456 } }
}
getFilterable - separate - ffaLeft - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getFilterable - separate - ffa1RightLeft - {
left: { _tag: 'Right', right: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ '' ] }
}
getFilterable - separate - ffa1RightRight - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 123 } }
}
---------
getWitherable - compact - foaLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getWitherable - compact - foaRightNone - { _tag: 'Left', left: [ '' ] }
getWitherable - compact - foa1RightSome - { _tag: 'Right', right: { Test2: 123 } }
getWitherable - filter - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getWitherable - filter - faLeft_extends - { _tag: 'Left', left: [ 'error fa1l' ] }
getWitherable - filter - fa1Right - { _tag: 'Left', left: [ '' ] }
getWitherable - filter - fa1right_extends - { _tag: 'Right', right: { Test2: 123, Test23: 'extends Test2<123>' } }
getWitherable - filter - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getWitherable - filter - fa1Right - { _tag: 'Left', left: [ '' ] }
getWitherable - filter - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
getWitherable - foldMap - faLeft - { Test2: '' }
getWitherable - foldMap - fa1Right - { Test2: '123' }
getWitherable - foldMap - fa2Right - { Test2: '456' }
getWitherable - map - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getWitherable - map - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
getWitherable - map - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
getWitherable - partition - faLeft - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getWitherable - partition - faLeft_extends - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getWitherable - partition - fa1Right - a_is_A_extends_refinement - {
left: { _tag: 'Right', right: { Test2: 123 } },
right: { _tag: 'Left', left: [ '' ] }
}
getWitherable - partition - fa1Right_extends - a_is_A_extends_refinement - {
left: { _tag: 'Left', left: [ '' ] },
right: {
_tag: 'Right',
right: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
getWitherable - partition - faLeft - a_is_bool_predicate - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getWitherable - partition - fa1Right - a_is_bool_predicate - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 123 } }
}
getWitherable - partition - fa2Right - a_is_bool_predicate - {
left: { _tag: 'Right', right: { Test2: 456 } },
right: { _tag: 'Left', left: [ '' ] }
}
getWitherable - partitionMap - faLeft - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getWitherable - partitionMap - fa1Right - {
left: { _tag: 'Right', right: [ '123', '<= odd number is ng' ] },
right: { _tag: 'Left', left: [ '' ] }
}
getWitherable - partitionMap - fa2Right - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 456 } }
}
getWitherable - reduce - faLeft - b1 - { Test2: 'abc' }
getWitherable - reduce - fa1Right - b1 - { Test2: 'abc :: 123' }
getWitherable - reduce - fa2Right - b1 - { Test2: 'abc :: 456' }
getWitherable - reduceRight - faLeft - b1 - { Test2: 'abc' }
getWitherable - reduceRight - fa1Right - b1 - { Test2: 'abc :: 123' }
getWitherable - reduceRight - fa2Right - b1 - { Test2: 'abc :: 456' }
getWitherable - separate - ffaLeft - {
left: { _tag: 'Left', left: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ 'error fa1l' ] }
}
getWitherable - separate - ffa1RightLeft - {
left: { _tag: 'Right', right: [ 'error fa1l' ] },
right: { _tag: 'Left', left: [ '' ] }
}
getWitherable - separate - ffa1RightRight - {
left: { _tag: 'Left', left: [ '' ] },
right: { _tag: 'Right', right: { Test2: 123 } }
}
getWitherable - sequence - faLeft - { Test2: { _tag: 'Left', left: [ 'error fa1l' ] } }
getWitherable - sequence - fa1Right - { Test2: { _tag: 'Right', right: 123 } }
getWitherable - sequence - fa2Right - { Test2: { _tag: 'Right', right: 456 } }
getWitherable - traverse - faLeft - { Test2: { _tag: 'Left', left: [ 'error fa1l' ] } }
getWitherable - traverse - fa1Right - { Test2: { _tag: 'Right', right: '123' } }
getWitherable - traverse - fa2Right - { Test2: { _tag: 'Right', right: '456' } }
getWitherable - wilt - faLeft - {
Test2: {
left: { _tag: 'Left', left: [Array] },
right: { _tag: 'Left', left: [Array] }
}
}
getWitherable - wilt - fa1Right - {
Test2: {
left: { _tag: 'Right', right: [Array] },
right: { _tag: 'Left', left: [Array] }
}
}
getWitherable - wilt - fa2Right - {
Test2: {
left: { _tag: 'Left', left: [Array] },
right: { _tag: 'Right', right: 456 }
}
}
getWitherable - wither - faLeft - { Test2: { _tag: 'Left', left: [ 'error fa1l' ] } }
getWitherable - wither - fa1Right - { Test2: { _tag: 'Left', left: [ '' ] } }
getWitherable - wither - fa2Right - { Test2: { _tag: 'Right', right: 456 } }
---------
getApplicativeValidation - ap - faLeft - f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l', 'error fa1l' ] }
getApplicativeValidation - ap - fa1Right - f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getApplicativeValidation - ap - fa2Right - f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getApplicativeValidation - ap - faLeft - f_a_bRight - { _tag: 'Left', left: [ 'error fa1l' ] }
getApplicativeValidation - ap - fa1Right - f_a_bRight - { _tag: 'Right', right: { Test2: '123' } }
getApplicativeValidation - ap - fa2Right - f_a_bRight - { _tag: 'Right', right: { Test2: '456' } }
getApplicativeValidation - ap - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getApplicativeValidation - ap - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
getApplicativeValidation - ap - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
getApplicativeValidation - of - faLeft - { _tag: 'Right', right: { _tag: 'Left', left: [ 'error fa1l' ] } }
getApplicativeValidation - of - fa1Right - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 123 } } }
getApplicativeValidation - of - fa2Right - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 456 } } }
getAltValidation - alt - faLeft - faLeft { _tag: 'Left', left: [ 'error fa1l', 'error fa1l' ] }
getAltValidation - alt - faLeft - fa1Right { _tag: 'Right', right: { Test2: 123 } }
getAltValidation - alt - fa1Right - faLeft { _tag: 'Right', right: { Test2: 123 } }
getAltValidation - alt - fa1Right - fa2Right { _tag: 'Right', right: { Test2: 123 } }
getAltValidation - map - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
getAltValidation - map - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
getAltValidation - map - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
---------
map - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
map - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
map - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
---------
Functor - map - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
Functor - map - fa1Right - { _tag: 'Right', right: { Test2: '123' } }
Functor - map - fa2Right - { _tag: 'Right', right: { Test2: '456' } }
---------
as - (faLeft, faLeft) - { _tag: 'Left', left: [ 'error fa1l' ] }
as - (faLeft, fa1Right) - { _tag: 'Left', left: [ 'error fa1l' ] }
as - (fa1Right, faLeft) - { _tag: 'Right', right: { _tag: 'Left', left: [ 'error fa1l' ] } }
as - (fa1Right, fa2Right) - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 456 } } }
as - (fa1Right, fa2Right) - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 456 } } }
---------
asUnit - faLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
asUnit - fa1Right - { _tag: 'Right', right: undefined }
---------
of - _a1 - { _tag: 'Right', right: 123 }
of - faLeft - { _tag: 'Right', right: { _tag: 'Left', left: [ 'error fa1l' ] } }
of - fa1Right - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 123 } } }
---------
Pointed - of - _a1 - { _tag: 'Right', right: 123 }
Pointed - of - faLeft - { _tag: 'Right', right: { _tag: 'Left', left: [ 'error fa1l' ] } }
Pointed - of - fa1Right - { _tag: 'Right', right: { _tag: 'Right', right: { Test2: 123 } } }
---------
apW - faLeft - f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
apW - fa1Right - f_a_bLeft - { _tag: 'Left', left: [ 'error fa1l' ] }
apW - faLeft - f_a_bRight - { _tag: 'Left', left: [ 'error fa1l' ] }
apW - fa1Right - f_a_bRight - { _tag: 'Right', right: { Test2: '123' } }
Eqの内容確認
参考
import { describe, it } from 'vitest'
import { pipe } from 'fp-ts/lib/function'
import * as E from 'fp-ts/Eq'
import * as N from 'fp-ts/number'
type Test2<A> = {
Test2: A
}
type Test3<A> = {
Test3: A
Sub: A
}
const TestEqNumber: E.Eq<number> = {
equals: (x: number, y: number) => x === y
}
const TestEqTest2Number: E.Eq<Test2<number>> = {
equals: (x: Test2<number>, y: Test2<number>) => x.Test2 === y.Test2
}
describe('fp-ts Tutorial', () => {
it('Eq', () => {
const eqTest2 = (x: Test2<number>, y: Test2<number>) => x.Test2 === y.Test2
const test2_1: Test2<number> = { Test2: 1 }
const test2_2: Test2<number> = { Test2: 2 }
const fromEquals = E.fromEquals<Test2<number>>(eqTest2)
console.log('fromEquals - ', fromEquals.equals(test2_1, test2_1))
console.log('fromEquals - ', fromEquals.equals(test2_1, test2_2))
const struct = E.struct({
Test2: TestEqNumber
})
console.log('struct - ', struct.equals(test2_1, test2_1))
console.log('struct - ', struct.equals(test2_1, test2_2))
const tuple = E.tuple(TestEqTest2Number, TestEqTest2Number)
console.log('tuple - ', tuple.equals([test2_1, test2_2], [test2_1, test2_2]))
console.log('tuple - ', tuple.equals([test2_1, test2_1], [test2_2, test2_2]))
// console.log('tuple - ', tuple.equals([test2_1, test2_1, test2_1], [test2_2, test2_2, test2_2])) <= error
// console.log('tuple - ', tuple.equals([test2_1], [test2_2])) <= error
const eqTest2Number: E.Eq<number> = N.Eq
const eqTest2ByKey: E.Eq<Test2<number>> = pipe(
eqTest2Number,
E.contramap((ts) => ts.Test2)
)
console.log('eqTest2ByKey - ', eqTest2ByKey.equals(test2_1, test2_1))
console.log('eqTest2ByKey - ', eqTest2ByKey.equals(test2_1, test2_2))
E.eqStrict.equals(test2_1, test2_2)
console.log('eqStrict - ', E.eqStrict.equals(test2_1, test2_1))
console.log('eqStrict - ', E.eqStrict.equals(test2_1, test2_2))
const eqTest3: E.Eq<Test3<number>> = pipe(
eqTest2Number,
E.contramap((ts) => ts.Test3)
)
const eqTest3Sub: E.Eq<Test3<number>> = pipe(
eqTest2Number,
E.contramap((ts) => ts.Sub)
)
const getSemigroup = E.getSemigroup<Test3<number>>().concat(eqTest3, eqTest3Sub)
const test3_11: Test3<number> = { Test3: 1, Sub: 1 }
const test3_12: Test3<number> = { Test3: 1, Sub: 2 }
const test3_21: Test3<number> = { Test3: 2, Sub: 1 }
const test3_22: Test3<number> = { Test3: 2, Sub: 2 }
console.log('getSemigroup - ', getSemigroup.equals(test3_11, test3_11))
console.log('getSemigroup - ', getSemigroup.equals(test3_11, test3_12))
console.log('getSemigroup - ', getSemigroup.equals(test3_11, test3_21))
console.log('getSemigroup - ', getSemigroup.equals(test3_11, test3_22))
const getMonoid = E.getMonoid<Test3<number>>().concat(eqTest3, eqTest3Sub)
console.log('getMonoid - ', getMonoid.equals(test3_11, test3_11))
console.log('getMonoid - ', getMonoid.equals(test3_11, test3_12))
console.log('getMonoid - ', getMonoid.equals(test3_11, test3_21))
console.log('getMonoid - ', getMonoid.equals(test3_11, test3_22))
})
})
実行結果
fromEquals - true
fromEquals - false
struct - true
struct - false
tuple - true
tuple - false
eqTest2ByKey - true
eqTest2ByKey - false
eqStrict - true
eqStrict - false
getSemigroup - true
getSemigroup - false
getSemigroup - false
getSemigroup - false
getMonoid - true
getMonoid - false
getMonoid - false
getMonoid - false
internalの内容確認はできない
参照しても中身を確認できない
Applicativeの内容確認
参考
import { describe, it } from 'vitest'
import * as A from 'fp-ts/Applicative'
import type { Applicative1 } from 'fp-ts/Applicative'
import * as M from 'fp-ts/Monoid'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
type Test2<A> = {
Test2: A
}
const TestApplicative1: Applicative1<URI> = {
URI,
ap: (fab, fa) => ({ Test2: fab.Test2(fa.Test2) }),
of: <A>(a: A) => ({ Test2: a }),
map: (fa, f) => ({ Test2: f(fa.Test2) })
}
describe('fp-ts Tutorial', () => {
it('Applicative', () => {
const test2_a: Test2<string> = { Test2: 'a' }
const test2_b: Test2<string> = { Test2: 'b' }
const monoidString: M.Monoid<string> = {
concat: (x, y) => `${x} - ${y}`,
empty: 'empty'
}
const getApplicativeMonoid = A.getApplicativeMonoid(TestApplicative1)
const stringToTest2Monoid = getApplicativeMonoid(monoidString)
console.log('stringToTest2Monoid - ', stringToTest2Monoid.concat(test2_a, test2_b))
})
})
実行結果
stringToTest2Monoid - { Test2: 'a - b' }
Contravariantの内容確認
参考
実行はできるが、エラーが出てしまう。どうやるのが正解かよくわからん
import { describe, it } from 'vitest'
import type { Contravariant1 } from 'fp-ts/Contravariant'
import { flow, pipe } from 'fp-ts/lib/function'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
type Test2<A> = {
Test2: (a: A) => string
}
const _contramap =
<B, A>(f: (b: B) => A) =>
(test2a: Test2<A>): Test2<B> =>
flow(f, test2a.Test2)
const TestApplicative1: Contravariant1<URI> = {
URI,
contramap: (fa, f) => pipe(fa, _contramap(f))
}
describe('fp-ts Tutorial', () => {
it('Contravariant', () => {
const stringToNumber: (s: string) => number = (s: string) => Number(s)
const numberToString: (n: number) => string = (n: number) => String(n)
const test2n: Test2<number> = { Test2: (a) => 'Test3 - number - ' + String(a) }
const test2s: Test2<string> = { Test2: (a) => 'Test3 - string - ' + a }
console.log('contramap - number - ', test2n.Test2(123))
console.log(
'contramap - number - ',
TestApplicative1.contramap<number, string>(test2n, stringToNumber)('123')
)
console.log('contramap - string - ', test2s.Test2('789'))
console.log(
'contramap - string - ',
TestApplicative1.contramap<string, number>(test2s, numberToString)(789)
)
})
})
実行結果
contramap - number - Test3 - number - 123
contramap - number - Test3 - number - 123
contramap - string - Test3 - string - 789
contramap - string - Test3 - string - 789
IOの内容確認
参考
import { describe, it } from 'vitest'
import * as I from 'fp-ts/IO'
import { pipe } from 'fp-ts/lib/function'
type Test2<A> = {
Test2: A
}
type A = Test2<number>
type B = Test2<string>
type F<A> = I.IO<A>
describe('fp-ts Tutorial', () => {
it('IO', () => {
const a: A = { Test2: 2 }
const fa: F<A> = () => a
const ffa: F<F<A>> = () => fa
const b: B = { Test2: 'b' }
const fb: F<B> = () => b
const a_b_double = (a: A): B => ({
Test2: `double of ${String(a.Test2)} = ${String(a.Test2 * 2)}`
})
const f_a_b_double: F<(a: A) => B> = () => a_b_double
const a_fb_double: (a: A) => F<B> = (a) => () => a_b_double(a)
const debug_log_fa = (prefix: string, fa: F<A>) => {
console.log(prefix + 'F<A> === IO<Test2<number>> - fa() -', fa())
}
const debug_log_fb = (prefix: string, fb: F<B>) => {
console.log(prefix + 'F<B> === IO<Test2<string>> - fb() -', fb())
}
const debug_log_fvoid = (prefix: string, fvoid: F<void>) => {
console.log(prefix + 'F<void> === IO<void> - fvoid() -', fvoid())
}
const debug_log_self_fa = (prefix: string, self_fa: (self: F<A>) => F<A>) => {
console.log(
prefix +
'(self: F<A>) => F<A> === (self: IO<Test2<number>>) => IO<Test2<number>> - self_fa(fa)() -',
self_fa(fa)()
)
}
const debug_log_dict = (prefix: string, dict: F<{}>) => {
console.log(prefix + 'F<{}> === IO<{}> - dict() -', dict())
}
debug_log_fb('map - ', pipe(fa, I.map(a_b_double)))
debug_log_fb('ap - ', pipe(f_a_b_double, I.ap(fa)))
debug_log_fa('of - ', pipe(a, I.of))
debug_log_fb('flatMap - 1 - ', pipe(fa, I.flatMap(a_fb_double)))
debug_log_fb('flatMap - 2 - ', I.flatMap(fa, a_fb_double))
debug_log_fa('flatten - 1 - ', I.flatten(ffa))
debug_log_fa('as - 1 - ', pipe(fb, I.as(a)))
debug_log_fa('as - 2 - ', I.as(fb, a))
debug_log_fvoid('asUnit - ', I.asUnit(fa))
debug_log_fb('flap - ', pipe(f_a_b_double, I.flap(a)))
debug_log_fa('apFirst - ', pipe(fa, I.apFirst(fb)))
debug_log_fb('apSecond - ', pipe(fa, I.apSecond(fb)))
debug_log_fa('tap - 1 - ', I.tap(fa, a_fb_double))
debug_log_self_fa('tap - 2 - ', I.tap(a_fb_double))
debug_log_dict('Do - ', I.Do)
debug_log_dict('bindTo - ', pipe(fa, I.bindTo('fa - bindTo')))
debug_log_dict('let - ', pipe(fa, I.let('fa - let - a_b_double', a_b_double)))
debug_log_dict('bind - ', pipe(fa, I.bind('fa - bind - a_fb_double', a_fb_double)))
debug_log_dict('apS - ', pipe(fa, I.apS('fa - apS - fb', fb)))
debug_log_dict('ApT - ', I.ApT)
debug_log_dict(
'traverseReadonlyNonEmptyArrayWithIndex - ',
pipe(
[a, a, a],
I.traverseReadonlyNonEmptyArrayWithIndex((i, a) => a_fb_double(a))
)
)
debug_log_dict(
'traverseReadonlyArrayWithIndex - ',
pipe(
[a, a, a],
I.traverseReadonlyArrayWithIndex((i, a) => a_fb_double(a))
)
)
debug_log_dict(
'traverseArrayWithIndex - ',
pipe(
[a, a, a],
I.traverseArrayWithIndex((i, a) => a_fb_double(a))
)
)
debug_log_dict('traverseArray - ', pipe([a, a, a], I.traverseArray(a_fb_double)))
})
})
実行結果
map - F<B> === IO<Test2<string>> - fb() - { Test2: 'double of 2 = 4' }
ap - F<B> === IO<Test2<string>> - fb() - { Test2: 'double of 2 = 4' }
of - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
flatMap - 1 - F<B> === IO<Test2<string>> - fb() - { Test2: 'double of 2 = 4' }
flatMap - 2 - F<B> === IO<Test2<string>> - fb() - { Test2: 'double of 2 = 4' }
flatten - 1 - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
as - 1 - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
as - 2 - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
asUnit - F<void> === IO<void> - fvoid() - undefined
flap - F<B> === IO<Test2<string>> - fb() - { Test2: 'double of 2 = 4' }
apFirst - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
apSecond - F<B> === IO<Test2<string>> - fb() - { Test2: 'b' }
tap - 1 - F<A> === IO<Test2<number>> - fa() - { Test2: 2 }
tap - 2 - (self: F<A>) => F<A> === (self: IO<Test2<number>>) => IO<Test2<number>> - self_fa(fa)() - { Test2: 2 }
Do - F<{}> === IO<{}> - dict() - {}
bindTo - F<{}> === IO<{}> - dict() - { 'fa - bindTo': { Test2: 2 } }
let - F<{}> === IO<{}> - dict() - { Test2: 2, 'fa - let - a_b_double': { Test2: 'double of 2 = 4' } }
bind - F<{}> === IO<{}> - dict() - { Test2: 2, 'fa - bind - a_fb_double': { Test2: 'double of 2 = 4' } }
apS - F<{}> === IO<{}> - dict() - { Test2: 2, 'fa - apS - fb': { Test2: 'b' } }
ApT - F<{}> === IO<{}> - dict() - []
traverseReadonlyNonEmptyArrayWithIndex - F<{}> === IO<{}> - dict() - [
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' }
]
traverseReadonlyArrayWithIndex - F<{}> === IO<{}> - dict() - [
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' }
]
traverseArrayWithIndex - F<{}> === IO<{}> - dict() - [
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' }
]
traverseArray - F<{}> === IO<{}> - dict() - [
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' },
{ Test2: 'double of 2 = 4' }
]
Monadの内容確認
参考
import { describe, it } from 'vitest'
import type { Monad1 } from 'fp-ts/Monad'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
type Test2<A> = {
Test2: A
}
type A = number
type B = string
type F<A> = Test2<A>
const TestMonad1: Monad1<URI> = {
URI,
map: (fa, a_b_function) => TestMonad1.of(a_b_function(fa.Test2)),
ap: (f_a_b_function, fa) => TestMonad1.of(f_a_b_function.Test2(fa.Test2)),
of: <A>(a: A) => ({ Test2: a }),
chain: (fa, a_fb_function) => a_fb_function(fa.Test2)
}
describe('fp-ts Tutorial', () => {
it('Monad', () => {
const a: A = 2
const fa: F<A> = TestMonad1.of(a)
// const ffa: F<F<A>> = TestMonad1.of(fa)
// const b: B = 'b'
// const fb: F<B> = TestMonad1.of(b)
const a_b_double = (a: A): B => `double of ${String(a)} = ${String(a * 2)}`
const f_a_b_double: F<(a: A) => B> = TestMonad1.of(a_b_double)
const a_fb_double: (a: A) => F<B> = (a) => TestMonad1.of(a_b_double(a))
console.log('map - ', TestMonad1.map(fa, a_b_double))
console.log('ap - ', TestMonad1.ap(f_a_b_double, fa))
console.log('chain - ', TestMonad1.chain(fa, a_fb_double))
})
})
実行結果
map - { Test2: 'double of 2 = 4' }
ap - { Test2: 'double of 2 = 4' }
chain - { Test2: 'double of 2 = 4' }
Ordの内容確認
参考
import { describe, it } from 'vitest'
import * as O from 'fp-ts/Ord'
type Test2<A> = {
Test2: A
}
type A = Test2<number>
type B = Test2<string>
type F<A> = O.Ord<A>
const TestOrdNumber: F<A> = {
compare: (first: A, second: A) =>
first.Test2 > second.Test2 ? 1 : first.Test2 < second.Test2 ? -1 : 0,
equals: (x: A, y: A) => x.Test2 === y.Test2
}
const TestOrdString: F<B> = {
compare: (first: B, second: B) =>
first.Test2 > second.Test2 ? 1 : first.Test2 < second.Test2 ? -1 : 0,
equals: (x: B, y: B) => x.Test2 === y.Test2
}
describe('fp-ts Tutorial', () => {
it('Ord', () => {
const xa: A = { Test2: 123 }
const ya: A = { Test2: 789 }
const xb: B = { Test2: 'abc' }
const yb: B = { Test2: 'xyz' }
const xb_for_xa: B = { Test2: '1' }
const yb_for_xb: B = { Test2: '9' }
const b_a_function: (b: B) => A = (b) => ({ Test2: Number(b.Test2) })
console.log('equalsDefault - xa,ya', O.equalsDefault(TestOrdNumber.compare)(xa, ya))
console.log('equalsDefault - xa,xa', O.equalsDefault(TestOrdNumber.compare)(xa, xa))
console.log('equalsDefault - ya,xa', O.equalsDefault(TestOrdNumber.compare)(ya, xa))
console.log('fromCompare - xa,ya', O.fromCompare(TestOrdNumber.compare).compare(xa, ya))
console.log('fromCompare - xa,xa', O.fromCompare(TestOrdNumber.compare).compare(xa, xa))
console.log('fromCompare - ya,xa', O.fromCompare(TestOrdNumber.compare).compare(ya, xa))
console.log(
'tuple - x3[xa, xb, xa] - y3[ya, yb, ya]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, xb, xa], [ya, yb, ya])
)
console.log(
'tuple - x2y1[xa, yb, xa] - x2y1[ya, xb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, yb, xa], [ya, xb, xa])
)
console.log(
'tuple - x2y1[xa, xb, ya] - x2y1[ya, xb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, xb, ya], [ya, xb, xa])
)
console.log(
'tuple - x2y1[xa, xb, ya] - x2y1[xa, yb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, xb, ya], [xa, yb, xa])
)
console.log(
'tuple - x3[xa, xb, xa] - x3[xa, xb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, xb, xa], [xa, xb, xa])
)
console.log(
'tuple - x2y1[ya, xb, xa] - x2y1[xa, yb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([ya, xb, xa], [xa, yb, xa])
)
console.log(
'tuple - x2y1[ya, xb, xa] - x2y1[xa, xb, ya]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([ya, xb, xa], [xa, xb, ya])
)
console.log(
'tuple - x2y1[xa, yb, xa] - x2y1[xa, xb, ya]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([xa, yb, xa], [xa, xb, ya])
)
console.log(
'tuple - y3[ya, yb, ya] - x3[xa, xb, xa]',
O.tuple(TestOrdNumber, TestOrdString, TestOrdNumber).compare([ya, yb, ya], [xa, xb, xa])
)
console.log('reverse - xa,ya', O.reverse(TestOrdNumber).compare(xa, ya))
console.log('reverse - xa,xa', O.reverse(TestOrdNumber).compare(xa, xa))
console.log('reverse - ya,xa', O.reverse(TestOrdNumber).compare(ya, xa))
console.log('contramap - ng - xb,yb', O.contramap(b_a_function)(TestOrdNumber).compare(xb, yb))
console.log('contramap - ng - xb,xb', O.contramap(b_a_function)(TestOrdNumber).compare(xb, xb))
console.log('contramap - ng - yb,xb', O.contramap(b_a_function)(TestOrdNumber).compare(yb, xb))
console.log('b_a_function(xb)', b_a_function(xb))
console.log('b_a_function(yb)', b_a_function(yb))
console.log(
'contramap - ok - xb,yb',
O.contramap(b_a_function)(TestOrdNumber).compare(xb_for_xa, yb_for_xb)
)
console.log(
'contramap - ok - xb,xb',
O.contramap(b_a_function)(TestOrdNumber).compare(xb_for_xa, xb_for_xa)
)
console.log(
'contramap - ok - yb,xb',
O.contramap(b_a_function)(TestOrdNumber).compare(yb_for_xb, xb_for_xa)
)
console.log('b_a_function(xb_for_xa)', b_a_function(xb_for_xa))
console.log('b_a_function(yb_for_xb)', b_a_function(yb_for_xb))
console.log(
'getSemigroup - xa,ya',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xa, ya)
)
console.log(
'getSemigroup - xa,xa',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xa, xa)
)
console.log(
'getSemigroup - ya,xa',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(ya, xa)
)
console.log(
'getSemigroup - xb,yb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xb, yb)
)
console.log(
'getSemigroup - xb,xb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xb, xb)
)
console.log(
'getSemigroup - yb,xb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(yb, xb)
)
console.log(
'getSemigroup - xa,yb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xa, yb)
)
console.log(
'getSemigroup - xa,xb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(xa, xb)
)
console.log(
'getSemigroup - ya,xb',
O.getSemigroup<any>().concat(TestOrdNumber, TestOrdString).compare(ya, xb)
)
console.log(
'getMonoid - xa,ya',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xa, ya)
)
console.log(
'getMonoid - xa,xa',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xa, xa)
)
console.log(
'getMonoid - ya,xa',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(ya, xa)
)
console.log(
'getMonoid - xb,yb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xb, yb)
)
console.log(
'getMonoid - xb,xb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xb, xb)
)
console.log(
'getMonoid - yb,xb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(yb, xb)
)
console.log(
'getMonoid - xa,yb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xa, yb)
)
console.log(
'getMonoid - xa,xb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(xa, xb)
)
console.log(
'getMonoid - ya,xb',
O.getMonoid<any>().concat(TestOrdNumber, TestOrdString).compare(ya, xb)
)
console.log(
'Contravariant - ok - xb,yb',
O.Contravariant.contramap(TestOrdNumber, b_a_function).compare(xb_for_xa, yb_for_xb)
)
console.log(
'Contravariant - ok - xb,xb',
O.Contravariant.contramap(TestOrdNumber, b_a_function).compare(xb_for_xa, xb_for_xa)
)
console.log(
'Contravariant - ok - yb,xb',
O.Contravariant.contramap(TestOrdNumber, b_a_function).compare(yb_for_xb, xb_for_xa)
)
console.log('trivial - xa,ya', O.trivial.compare(xa, ya))
console.log('trivial - xa,xa', O.trivial.compare(xa, xa))
console.log('trivial - ya,xa', O.trivial.compare(ya, xa))
console.log('trivial - xb,yb', O.trivial.compare(xb, yb))
console.log('trivial - xb,xb', O.trivial.compare(xb, xb))
console.log('trivial - yb,xb', O.trivial.compare(yb, xb))
console.log('equals - xa,ya', O.equals(TestOrdNumber)(ya)(xa))
console.log('equals - xa,xa', O.equals(TestOrdNumber)(xa)(xa))
console.log('equals - ya,xa', O.equals(TestOrdNumber)(xa)(ya))
console.log('lt - xa,ya', O.lt(TestOrdNumber)(xa, ya))
console.log('lt - xa,xa', O.lt(TestOrdNumber)(xa, xa))
console.log('lt - ya,xa', O.lt(TestOrdNumber)(ya, xa))
console.log('gt - xa,ya', O.gt(TestOrdNumber)(xa, ya))
console.log('gt - xa,xa', O.gt(TestOrdNumber)(xa, xa))
console.log('gt - ya,xa', O.gt(TestOrdNumber)(ya, xa))
console.log('leq - xa,ya', O.leq(TestOrdNumber)(xa, ya))
console.log('leq - xa,xa', O.leq(TestOrdNumber)(xa, xa))
console.log('leq - ya,xa', O.leq(TestOrdNumber)(ya, xa))
console.log('geq - xa,ya', O.geq(TestOrdNumber)(xa, ya))
console.log('geq - xa,xa', O.geq(TestOrdNumber)(xa, xa))
console.log('geq - ya,xa', O.geq(TestOrdNumber)(ya, xa))
console.log('min - xa,ya', O.min(TestOrdNumber)(xa, ya))
console.log('min - xa,xa', O.min(TestOrdNumber)(xa, xa))
console.log('min - ya,xa', O.min(TestOrdNumber)(ya, xa))
console.log('max - xa,ya', O.max(TestOrdNumber)(xa, ya))
console.log('max - xa,xa', O.max(TestOrdNumber)(xa, xa))
console.log('max - ya,xa', O.max(TestOrdNumber)(ya, xa))
console.log('clamp - (xa,ya) - xa', O.clamp(TestOrdNumber)(xa, ya)(xa))
console.log('clamp - (xa,xa) - xa', O.clamp(TestOrdNumber)(xa, xa)(xa))
console.log('clamp - (ya,xa) - xa', O.clamp(TestOrdNumber)(ya, xa)(xa))
console.log('clamp - (xa,ya) - ya', O.clamp(TestOrdNumber)(xa, ya)(ya))
console.log('clamp - (xa,xa) - ya', O.clamp(TestOrdNumber)(xa, xa)(ya))
console.log('clamp - (ya,xa) - ya', O.clamp(TestOrdNumber)(ya, xa)(ya))
console.log('between - (xa,ya) - xa', O.between(TestOrdNumber)(xa, ya)(xa))
console.log('between - (xa,xa) - xa', O.between(TestOrdNumber)(xa, xa)(xa))
console.log('between - (ya,xa) - xa', O.between(TestOrdNumber)(ya, xa)(xa))
console.log('between - (xa,ya) - ya', O.between(TestOrdNumber)(xa, ya)(ya))
console.log('between - (xa,xa) - ya', O.between(TestOrdNumber)(xa, xa)(ya))
console.log('between - (ya,xa) - ya', O.between(TestOrdNumber)(ya, xa)(ya))
})
})
実行結果
equalsDefault - xa,ya false
equalsDefault - xa,xa true
equalsDefault - ya,xa false
fromCompare - xa,ya -1
fromCompare - xa,xa 0
fromCompare - ya,xa 1
tuple - x3[xa, xb, xa] - y3[ya, yb, ya] -1
tuple - x2y1[xa, yb, xa] - x2y1[ya, xb, xa] -1
tuple - x2y1[xa, xb, ya] - x2y1[ya, xb, xa] -1
tuple - x2y1[xa, xb, ya] - x2y1[xa, yb, xa] -1
tuple - x3[xa, xb, xa] - x3[xa, xb, xa] 0
tuple - x2y1[ya, xb, xa] - x2y1[xa, yb, xa] 1
tuple - x2y1[ya, xb, xa] - x2y1[xa, xb, ya] 1
tuple - x2y1[xa, yb, xa] - x2y1[xa, xb, ya] 1
tuple - y3[ya, yb, ya] - x3[xa, xb, xa] 1
reverse - xa,ya 1
reverse - xa,xa 0
reverse - ya,xa -1
contramap - ng - xb,yb 0
contramap - ng - xb,xb 0
contramap - ng - yb,xb 0
b_a_function(xb) { Test2: NaN }
b_a_function(yb) { Test2: NaN }
contramap - ok - xb,yb -1
contramap - ok - xb,xb 0
contramap - ok - yb,xb 1
b_a_function(xb_for_xa) { Test2: 1 }
b_a_function(yb_for_xb) { Test2: 9 }
getSemigroup - xa,ya -1
getSemigroup - xa,xa 0
getSemigroup - ya,xa 1
getSemigroup - xb,yb -1
getSemigroup - xb,xb 0
getSemigroup - yb,xb 1
getSemigroup - xa,yb 0
getSemigroup - xa,xb 0
getSemigroup - ya,xb 0
getMonoid - xa,ya -1
getMonoid - xa,xa 0
getMonoid - ya,xa 1
getMonoid - xb,yb -1
getMonoid - xb,xb 0
getMonoid - yb,xb 1
getMonoid - xa,yb 0
getMonoid - xa,xb 0
getMonoid - ya,xb 0
Contravariant - ok - xb,yb -1
Contravariant - ok - xb,xb 0
Contravariant - ok - yb,xb 1
trivial - xa,ya 0
trivial - xa,xa 0
trivial - ya,xa 0
trivial - xb,yb 0
trivial - xb,xb 0
trivial - yb,xb 0
equals - xa,ya false
equals - xa,xa true
equals - ya,xa false
lt - xa,ya true
lt - xa,xa false
lt - ya,xa false
gt - xa,ya false
gt - xa,xa false
gt - ya,xa true
leq - xa,ya true
leq - xa,xa true
leq - ya,xa false
geq - xa,ya false
geq - xa,xa true
geq - ya,xa true
min - xa,ya { Test2: 123 }
min - xa,xa { Test2: 123 }
min - ya,xa { Test2: 123 }
max - xa,ya { Test2: 789 }
max - xa,xa { Test2: 123 }
max - ya,xa { Test2: 789 }
clamp - (xa,ya) - xa { Test2: 123 }
clamp - (xa,xa) - xa { Test2: 123 }
clamp - (ya,xa) - xa { Test2: 789 }
clamp - (xa,ya) - ya { Test2: 789 }
clamp - (xa,xa) - ya { Test2: 123 }
clamp - (ya,xa) - ya { Test2: 789 }
between - (xa,ya) - xa true
between - (xa,xa) - xa true
between - (ya,xa) - xa false
between - (xa,ya) - ya true
between - (xa,xa) - ya false
between - (ya,xa) - ya false
ReadonlyRecordの内容確認
参考
import { describe, it } from 'vitest'
import * as R from 'fp-ts/ReadonlyRecord'
import * as O from 'fp-ts/Option'
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/lib/function'
import type { Unfoldable1 } from 'fp-ts/Unfoldable'
import type { Eq } from 'fp-ts/lib/Eq'
import type { Ord } from 'fp-ts/Ord'
import type { Monoid } from 'fp-ts/lib/Monoid'
import type { Applicative1 } from 'fp-ts/lib/Applicative'
import type { Option } from 'fp-ts/Option'
import type { Either } from 'fp-ts/lib/Either'
import type { Foldable1 } from 'fp-ts/lib/Foldable'
import type { Magma } from 'fp-ts/lib/Magma'
import type { Show } from 'fp-ts/lib/Show'
import type { Semigroup } from 'fp-ts/lib/Semigroup'
const URI = 'Test2'
type URI = typeof URI
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly Test2: Test2<A>
}
}
const TestUnfoldable1: Unfoldable1<URI> = {
URI,
unfold: (b, f) => {
let a
const option_a_b = f(b)
if (O.isSome(option_a_b)) {
a = option_a_b.value[0]
} else {
a = null as any
}
return a
}
}
const TestApplicative1Test2a: Applicative1<URI> = {
URI,
ap: (fab, fa) => ({ Test2: fab.Test2(fa.Test2) }),
of: <XXX>(a: XXX) => ({ Test2: a }),
map: (fa, f) => ({ Test2: f(fa.Test2) })
}
const TestFoldable1Test2a: Foldable1<URI> = {
URI,
reduce: (fa, b, f) => f(b, fa.Test2),
foldMap: (M) => (fa, f) => f(fa.Test2),
reduceRight: (fa, b, f) => f(fa.Test2, b)
}
interface Test2<XXX> {
Test2: XXX
}
interface Test23<XXX> extends Test2<XXX> {
Test23: `extends Test2<${XXX extends string ? XXX : XXX extends number ? XXX : 'something'}>`
}
type _a = number
type _b = string
type A = Test2<_a>
type B = Test2<_b>
// T = tuple, K = key = string
type TKA = readonly [string, A]
type A_extends = Test23<_a>
type BO = Test2<Option<_b>>
type OB = Option<B>
type Eb<XXX> = Either<XXX, _b>
type BEb<XXX> = Test2<Eb<XXX>>
type F<XXX> = R.ReadonlyRecord<string, XXX>
type FO<XXX> = F<Option<XXX>>
type FE<XXX, YYY> = F<Either<XXX, YYY>>
type T2_TKA = Test2<TKA>
type T2_A = Test2<A>
const TestEqTest2A: Eq<A> = {
equals: (x, y) => x.Test2 === y.Test2
}
const TestMagmaTest2a: Magma<A> = {
concat: (x, y) => ({
Test2: x.Test2 + y.Test2
})
}
const TestSemigroupTest2a: Semigroup<A> = {
concat: TestMagmaTest2a.concat
}
const TestMonoidTest2a: Monoid<A> = {
concat: TestMagmaTest2a.concat,
empty: {
Test2: 0
}
}
const TestShowTest2a: Show<A> = {
show: (a: A) => String(a.Test2)
}
const OrdString: Ord<string> = {
compare: (first: string, second: string) => (first > second ? 1 : first < second ? -1 : 0),
equals: (x: string, y: string) => x === y
}
describe('fp-ts Tutorial', () => {
it('ReadonlyRecord', () => {
const a: A = { Test2: 123 }
const a2: A = { Test2: 456 }
const a3: A = { Test2: 789 }
const a111: A = { Test2: 111 }
const a999: A = TestApplicative1Test2a.of(999) // { Test2: 999 }
const a_ext_123: A_extends = { Test2: 123, Test23: 'extends Test2<123>' }
const a_ext_456: A_extends = { Test2: 456, Test23: 'extends Test2<456>' }
const a_ext_789: A_extends = { Test2: 789, Test23: 'extends Test2<789>' }
const fa3: F<A> = {
key1: a,
key2: a2,
key3: a3
}
const fa2: F<A> = {
key1: a,
key2: a2
}
const fa2_111: F<A> = {
key1: a111,
key2: a2
}
const fa3_k: F<A> = {
k1: a,
k2: a2,
k3: a3
}
const fa6: F<A> = {
key1: a,
key2: a2,
key3: a3,
key1_extends: a_ext_123,
key2_extends: a_ext_456,
key3_extends: a_ext_789
}
const fa6_ng: F<A> = {
key1: a,
key2: a2,
key3: a3,
key1_extends: a,
key2_extends: a2,
key3_extends: a3
}
const fa_extends_6: F<A_extends> = {
key1_extends: a_ext_123,
key2_extends: a_ext_456,
key3_extends: a_ext_789
}
const foa6: FO<A> = {
key1: O.some(a),
key2: O.none,
key3: O.some(a3),
key1_extends: O.none,
key2_extends: O.some(a_ext_456),
key3_extends: O.some(a_ext_789)
}
const fea6: FE<string[], A> = {
key1: E.left([String(a.Test2), 'key1 includes 1', 'fea6[key1]']),
key2: E.left([String(a2.Test2), '456 is even number', 'fea6[key2]']),
key3: E.right(a3),
key1_extends: E.right(a_ext_123),
key2_extends: E.left([
String(a_ext_456.Test2),
'key1 includes 2',
'fea6[key2_extends]',
a_ext_456.Test23
]),
key3_extends: E.left([
String(a_ext_789.Test2),
'789 above 500',
'fea6[key3_extends]',
a_ext_789.Test23
])
}
const b: B = { Test2: 'abc' }
// const b_null: B = { Test2: 'b is null' }
const b_null: B = TestApplicative1Test2a.of('b is null')
const tka: TKA = ['key1', a]
const tka2: TKA = ['key2', a2]
const tka3: TKA = ['key3', a3]
const t2_tka: T2_TKA = {
Test2: tka
}
const t2_a: T2_A = {
Test2: a
}
// refinement, predicate
const a_is_A_extends_refinement = (a: A): a is A_extends => 'Test23' in a
const ia_refinement_A_extends = <I>(i: I, a: A): a is A_extends => a_is_A_extends_refinement(a)
const a_is_bool_predicate = (a: A): boolean => a.Test2 % 2 === 1
const ia_predicate_a_is_bool = <I>(i: I, a: A): boolean => a_is_bool_predicate(a)
// a function
const a_a_function: (a: A) => A = (a) => ({
Test2: a.Test2
})
const a_b_function: (a: A) => B = (a) => ({
Test2: `${a.Test2}`
})
const a_extends_b_function: (a: A_extends) => B = (a) => ({
Test2: `${a.Test2}-${a.Test23}`
})
const a_bo_function: (a: A) => BO = (a) => ({
Test2: a.Test2 % 2 === 0 ? O.none : O.some(a_b_function(a).Test2)
})
const a_Ebx_function: (a: A) => Eb<string[]> = (a) =>
a.Test2 % 2 === 0
? E.left([a_b_function(a).Test2, '<== even number is error', 'a_Ebx_function'])
: E.right(a_b_function(a).Test2)
const a_BEbx_function: (a: A) => BEb<string[]> = (a) => ({
Test2: a_Ebx_function(a)
})
const a_ob_function: (a: A) => OB = (a) => O.some(a_b_function(a))
const a_tka_function: (a: A) => TKA = (a) => ['a_tka_function', a]
// ab function
const ba_b_function: (b: B, a: A) => B = (b, a) => ({
Test2: `${b.Test2} :: ${a_b_function(a).Test2}`
})
const ab_b_function: (a: A, b: B) => B = (a, b) => ba_b_function(b, a)
// ia function
const ia_a_function: <I>(i: I, a: A) => A = (i, a) =>
typeof i === 'string'
? {
Test2: a.Test2 + i.length * 10 ** 5
}
: typeof i === 'number'
? {
Test2: a.Test2 + i * 10 ** 5
}
: a
const ia_b_function: <I>(i: I, a: A) => B = (i, a) => ({
Test2: `(${i},${a_b_function(a).Test2})`
})
const ia_ob_function: <I>(i: I, a: A) => OB = (i, a) =>
typeof i === 'string' && i.includes('1') ? O.none : O.some(ia_b_function(i, a))
const ia_Ebx_function: <I>(i: I, a: A) => Eb<string[]> = (i, a) =>
typeof i === 'string' && i.includes('1')
? E.left([i, '<== key includes 1', 'ia_Ebx_function'])
: a_Ebx_function(a)
// iab function
const iba_b_function: <I>(i: I, b: B, a: A) => B = (i, b, a) => ({
Test2: `${b.Test2} :: ${ia_b_function(i, a).Test2}`
})
const iab_b_function: <I>(i: I, a: A, b: B) => B = (i, a, b) => iba_b_function(i, b, a)
// ka function
const ka_a_function: <K extends string>(k: K, a: A) => A = ia_a_function
const ka_b_function: <K extends string>(k: K, a: A) => B = ia_b_function
const ka_Ebx_function: <K extends string>(k: K, a: A) => Eb<string[]> = ia_Ebx_function
const ka_ob_function: <K extends string>(k: K, a: A) => OB = ia_ob_function
// kab function
const kba_b_function: <K extends string>(k: K, b: B, a: A) => B = iba_b_function
const kab_b_function: <K extends string>(k: K, a: A, b: B) => B = iab_b_function
// fa function object
const fa_b_function: (key: keyof F<A>) => (fa: F<A>) => B = (key) => (fa) =>
key in fa ? a_b_function(fa[key]) : b_null
const fa_extends_b_function: (key: keyof F<A>) => (fa_extends: F<A_extends>) => B =
(key) => (fa_extends) => (key in fa_extends ? a_extends_b_function(fa_extends[key]) : b_null)
const fa_b_function_object: F<(fa: F<A>) => B> = {
key1: fa_b_function('key1'),
key2: fa_b_function('key2'),
key3: fa_b_function('key3'),
key1_extends: fa_b_function('key1_extends'),
key2_extends: fa_b_function('key2_extends'),
key3_extends: fa_b_function('key3_extends')
}
const fa_extends_b_function_object: F<(a: F<A_extends>) => B> = {
key1: fa_b_function('key1'),
key2: fa_b_function('key2'),
key3: fa_extends_b_function('key3'),
key1_extends: fa_extends_b_function('key1_extends'),
key2_extends: fa_b_function('key2_extends'),
key3_extends: fa_b_function('key3_extends')
}
// check
console.log('a - ', a)
console.log('b - ', b)
console.log('fa3 - ', fa3)
console.log('fa6 - ', fa6)
console.log('foa6 - ', foa6)
console.log('tka - ', tka)
console.log('t2_tka - ', t2_tka)
console.log('t2_a - ', t2_a)
// test
console.log('isEmpty - ', R.isEmpty(fa3))
console.log('keys - ', R.keys(fa3))
console.log('collect - ', pipe(fa3, R.collect(OrdString)(ka_b_function)))
console.log('toReadonlyArray - ', R.toReadonlyArray(fa3))
console.log('toUnfoldable - ', pipe(fa3, R.toUnfoldable(TestUnfoldable1)))
console.log('upsertAt - ', pipe(fa3, R.upsertAt('add key9', a999)))
console.log('has - key1 - ', R.has('key1', fa3))
console.log('has - key999 - ', R.has('key999', fa3))
console.log('deleteAt - key1 - ', pipe(fa3, R.deleteAt('key1')))
console.log('deleteAt - key999 - ', pipe(fa3, R.deleteAt('key999')))
console.log('updateAt - key1 - ', pipe(fa3, R.updateAt('key1', a111)))
console.log('updateAt - key999 - ', pipe(fa3, R.updateAt('key999', a999)))
console.log('modifyAt - key1 - ', pipe(fa3, R.modifyAt('key1', a_a_function)))
console.log('modifyAt - key999 - ', pipe(fa3, R.modifyAt('key999', a_a_function)))
console.log('pop - key1 - ', pipe(fa3, R.pop('key1')))
console.log('pop - key999 - ', pipe(fa3, R.pop('key999')))
console.log('isSubrecord - fa3,fa3 - ', R.isSubrecord(TestEqTest2A)(fa3)(fa3))
console.log('isSubrecord - fa3,fa2 - ', R.isSubrecord(TestEqTest2A)(fa3)(fa2))
console.log('isSubrecord - fa2,fa3 - ', R.isSubrecord(TestEqTest2A)(fa2)(fa3))
console.log('isSubrecord - fa3,fa2_111 - ', R.isSubrecord(TestEqTest2A)(fa3)(fa2_111))
console.log('isSubrecord - fa3,fa3 - ', pipe(fa3, R.isSubrecord(TestEqTest2A)(fa3)))
console.log('isSubrecord - fa3,fa2 - ', pipe(fa2, R.isSubrecord(TestEqTest2A)(fa3)))
console.log('isSubrecord - fa2,fa3 - ', pipe(fa3, R.isSubrecord(TestEqTest2A)(fa2)))
console.log('isSubrecord - fa3,fa2_111 - ', pipe(fa2_111, R.isSubrecord(TestEqTest2A)(fa3)))
console.log('isSubrecord - key1 - ', pipe(fa3, R.lookup('key1')))
console.log('isSubrecord - key999 - ', pipe(fa3, R.lookup('key999')))
console.log('isSubrecord - key1 - ', R.lookup('key1', fa3))
console.log('isSubrecord - key999 - ', R.lookup('key999', fa3))
console.log('empty - ', R.empty)
console.log('mapWithIndex - ', pipe(fa3, R.mapWithIndex(ka_b_function)))
console.log('map - ', pipe(fa3, R.map(a_b_function)))
console.log('reduceWithIndex - ', pipe(fa3, R.reduceWithIndex(OrdString)(b, kba_b_function)))
console.log(
'foldMapWithIndex - [12]0[1368] - [12 = key1(4) + key2(4) + key3(4)] - [1368 = 123 + 456 + 789]',
pipe(fa3, R.foldMapWithIndex(OrdString)(TestMonoidTest2a)(ka_a_function))
)
console.log(
'reduceRightWithIndex - ',
pipe(fa3, R.reduceRightWithIndex(OrdString)(b, kab_b_function))
)
console.log('singleton - ', R.singleton('key1', a))
console.log(
'traverseWithIndex - ',
pipe(fa3, R.traverseWithIndex(TestApplicative1Test2a)(ka_b_function))
)
console.log('traverse - ', pipe(fa3, R.traverse(TestApplicative1Test2a)(a_b_function)))
console.log('sequence - ', pipe(fa3, R.sequence(TestApplicative1Test2a)))
console.log('wither - ', pipe(fa3, R.wither(TestApplicative1Test2a)(a_bo_function)))
console.log('wilt - ', pipe(fa3, R.wilt(TestApplicative1Test2a)(a_BEbx_function)))
console.log('partitionMapWithIndex - ', pipe(fa6, R.partitionMapWithIndex(ka_Ebx_function)))
console.log(
'partitionWithIndex - ia_refinement_A_extends - ',
pipe(fa6, R.partitionWithIndex(ia_refinement_A_extends))
)
console.log(
'partitionWithIndex - ia_predicate_a_is_bool - ',
pipe(fa6, R.partitionWithIndex(ia_predicate_a_is_bool))
)
console.log('filterMapWithIndex - ', pipe(fa6, R.filterMapWithIndex(ka_ob_function)))
console.log(
'filterWithIndex - ia_refinement_A_extends - ',
pipe(fa6, R.filterWithIndex(ia_refinement_A_extends))
)
console.log(
'filterWithIndex - ia_predicate_a_is_bool - ',
pipe(fa6, R.filterWithIndex(ia_predicate_a_is_bool))
)
console.log(
'fromFoldable - ',
pipe(t2_tka, R.fromFoldable(TestMagmaTest2a, TestFoldable1Test2a))
)
console.log(
'fromFoldableMap - ',
R.fromFoldableMap(TestMagmaTest2a, TestFoldable1Test2a)(t2_a, a_tka_function)
)
console.log('toEntries - ', pipe(fa6, R.toEntries))
console.log('fromEntries - ', pipe([tka, tka2, tka3], R.fromEntries))
console.log('every - ', pipe(fa6, R.every(a_is_A_extends_refinement)))
console.log('some - ', pipe(fa6, R.some(a_is_A_extends_refinement)))
console.log('elem - fa6,a - ', pipe(fa6, R.elem(TestEqTest2A)(a)))
console.log('elem - fa6,a111 - ', pipe(fa6, R.elem(TestEqTest2A)(a111)))
console.log('elem - fa6,a - ', R.elem(TestEqTest2A)(a, fa6))
console.log('elem - fa6,a111 - ', R.elem(TestEqTest2A)(a111, fa6))
console.log(
'union - (fa6, fa2_111) => [234 = 123 + 111], [912 = 456 + 456] - ',
pipe(fa6, R.union(TestMagmaTest2a)(fa2_111))
)
console.log('union - (fa6, fa3_k) - ', pipe(fa6, R.union(TestMagmaTest2a)(fa3_k)))
console.log(
'intersection - (fa6, fa2_111) => [234 = 123 + 111], [912 = 456 + 456] - ',
pipe(fa6, R.intersection(TestMagmaTest2a)(fa2_111))
)
console.log('intersection - (fa6, fa3_k) - ', pipe(fa6, R.intersection(TestMagmaTest2a)(fa3_k)))
console.log('difference - (fa6, fa2_111) - ', pipe(fa6, R.difference(fa2_111)))
console.log('difference - (fa6, fa3_k) - ', pipe(fa6, R.difference(fa3_k)))
console.log(
'filter - a_is_A_extends_refinement - ',
pipe(fa6, R.filter(a_is_A_extends_refinement))
)
console.log('filter - a_is_bool_predicate - ', pipe(fa6, R.filter(a_is_bool_predicate)))
console.log('filterMap - ', pipe(fa6, R.filterMap(a_ob_function)))
console.log(
'partition - a_is_A_extends_refinement - ',
pipe(fa6, R.partition(a_is_A_extends_refinement))
)
console.log('partition - a_is_bool_predicate - ', pipe(fa6, R.partition(a_is_bool_predicate)))
console.log('partitionMap - ', pipe(fa6, R.partitionMap(a_Ebx_function)))
console.log('reduce - ', pipe(fa3, R.reduce(OrdString)(b, ba_b_function)))
console.log(
'foldMap - [1368 = 123 + 456 + 789] - ',
pipe(fa3, R.foldMap(OrdString)(TestMonoidTest2a)(a_a_function))
)
console.log('reduceRight - ', pipe(fa3, R.reduceRight(OrdString)(b, ab_b_function)))
console.log('compact - ', pipe(foa6, R.compact))
console.log('separate - ', pipe(fea6, R.separate))
console.log('getShow - ', pipe(fa6, R.getShow(OrdString)(TestShowTest2a).show))
console.log('getEq - (fa6, fa3) - ', R.getEq(TestEqTest2A).equals(fa6, fa3))
console.log('getEq - (fa6, fa6_ng) - ', R.getEq(TestEqTest2A).equals(fa6, fa6_ng))
console.log('getEq - (fa6, fa6) - ', R.getEq(TestEqTest2A).equals(fa6, fa6))
console.log(
'getMonoid - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - ',
R.getMonoid(TestSemigroupTest2a).concat(fa6, fa3)
)
console.log('getMonoid - (fa6, fa3_k) - ', R.getMonoid(TestSemigroupTest2a).concat(fa6, fa3_k))
console.log('map - (fa6, a_a_function) - ', R.Functor.map(fa6, a_a_function))
console.log('map - (fa6, a_b_function) - ', R.Functor.map(fa6, a_b_function))
console.log('flap - (fa6, fa_b_function_object) - ', pipe(fa_b_function_object, R.flap(fa6)))
console.log(
'flap - (fa_extends_6, fa_extends_b_function_object) - ',
pipe(fa_extends_b_function_object, pipe(fa_extends_6, R.flap))
)
console.log('FunctorWithIndex - map - ', R.FunctorWithIndex.map(fa6, a_b_function))
console.log(
'FunctorWithIndex - mapWithIndex - ',
R.FunctorWithIndex.mapWithIndex(fa6, ia_b_function)
)
console.log(
'getFoldable - foldMap - [2736 <= (123 + 456 + 789) * 2] - ',
R.getFoldable(OrdString).foldMap(TestMonoidTest2a)(fa6, a_a_function)
)
console.log('getFoldable - reduce - ', R.getFoldable(OrdString).reduce(fa6, b, ba_b_function))
console.log(
'getFoldable - reduceRight - ',
R.getFoldable(OrdString).reduceRight(fa6, b, ab_b_function)
)
console.log(
'getFoldableWithIndex - foldMapWithIndex - [48]0[2736] - [48 = key1(4) + key2(4) + key3(4) + key1_extends(12) + key2_extends(12) + key3_extends(12)] - [2736 <= (123 + 456 + 789) * 2] - ',
R.getFoldableWithIndex(OrdString).foldMapWithIndex(TestMonoidTest2a)(fa6, ia_a_function)
)
console.log(
'getFoldableWithIndex - reduceWithIndex - ',
R.getFoldableWithIndex(OrdString).reduceWithIndex(fa6, b, iba_b_function)
)
console.log(
'getFoldableWithIndex - reduceRightWithIndex - ',
R.getFoldableWithIndex(OrdString).reduceRightWithIndex(fa6, b, iab_b_function)
)
console.log('Compactable - compact - ', pipe(foa6, R.Compactable.compact))
console.log('Compactable - separate - ', pipe(fea6, R.Compactable.separate))
console.log('Filterable - compact - ', pipe(foa6, R.Filterable.compact))
console.log(
'Filterable - filter - a_is_A_extends_refinement - ',
R.Filterable.filter(fa6, a_is_A_extends_refinement)
)
console.log(
'Filterable - filter - a_is_bool_predicate - ',
R.Filterable.filter(fa6, a_is_bool_predicate)
)
console.log('Filterable - filterMap - ', R.Filterable.filterMap(fa6, a_ob_function))
console.log('Filterable - map - ', R.Filterable.map(fa6, a_b_function))
console.log(
'Filterable - partition - a_is_A_extends_refinement - ',
R.Filterable.partition(fa6, a_is_A_extends_refinement)
)
console.log(
'Filterable - partition - a_is_bool_predicate - ',
R.Filterable.partition(fa6, a_is_bool_predicate)
)
console.log('Filterable - partitionMap - ', R.Filterable.partitionMap(fa6, a_Ebx_function))
console.log('Filterable - separate - ', pipe(fea6, R.Filterable.separate))
console.log(
'FilterableWithIndex - filterMapWithIndex - ',
R.FilterableWithIndex.filterMapWithIndex(fa6, ia_ob_function)
)
console.log(
'FilterableWithIndex - filterWithIndex - ia_refinement_A_extends - ',
R.FilterableWithIndex.filterWithIndex(fa6, ia_refinement_A_extends)
)
console.log(
'FilterableWithIndex - filterWithIndex - ia_predicate_a_is_bool - ',
R.FilterableWithIndex.filterWithIndex(fa6, ia_predicate_a_is_bool)
)
console.log(
'FilterableWithIndex - mapWithIndex - ',
R.FilterableWithIndex.mapWithIndex(fa6, ia_b_function)
)
console.log(
'FilterableWithIndex - partitionMapWithIndex - ',
R.FilterableWithIndex.partitionMapWithIndex(fa6, ia_Ebx_function)
)
console.log(
'FilterableWithIndex - partitionWithIndex - ia_refinement_A_extends - ',
R.FilterableWithIndex.partitionWithIndex(fa6, ia_refinement_A_extends)
)
console.log(
'FilterableWithIndex - partitionWithIndex - ia_predicate_a_is_bool - ',
R.FilterableWithIndex.partitionWithIndex(fa6, ia_predicate_a_is_bool)
)
console.log(
'getTraversable - foldMap - [2736 <= (123 + 456 + 789) * 2] - ',
R.getTraversable(OrdString).foldMap(TestMonoidTest2a)(fa6, a_a_function)
)
console.log('getTraversable - map - ', R.getTraversable(OrdString).map(fa6, a_b_function))
console.log(
'getTraversable - reduce - ',
R.getTraversable(OrdString).reduce(fa6, b, ba_b_function)
)
console.log(
'getTraversable - reduceRight - ',
R.getTraversable(OrdString).reduceRight(fa6, b, ab_b_function)
)
console.log(
'getTraversable - sequence - ',
pipe(fa6, R.getTraversable(OrdString).sequence(TestApplicative1Test2a))
)
console.log(
'getTraversable - traverse - ',
R.getTraversable(OrdString).traverse(TestApplicative1Test2a)(fa6, a_b_function)
)
console.log(
'getTraversableWithIndex - foldMapWithIndex - [48]0[2736] - [48 = key1(4) + key2(4) + key3(4) + key1_extends(12) + key2_extends(12) + key3_extends(12)] - [2736 <= (123 + 456 + 789) * 2] - ',
R.getTraversableWithIndex(OrdString).foldMapWithIndex(TestMonoidTest2a)(fa6, ia_a_function)
)
console.log(
'getTraversableWithIndex - mapWithIndex - ',
R.getTraversableWithIndex(OrdString).mapWithIndex(fa6, ia_b_function)
)
console.log(
'getTraversableWithIndex - reduceRightWithIndex - ',
R.getTraversableWithIndex(OrdString).reduceRightWithIndex(fa6, b, iab_b_function)
)
console.log(
'getTraversableWithIndex - reduceWithIndex - ',
R.getTraversableWithIndex(OrdString).reduceWithIndex(fa6, b, iba_b_function)
)
console.log(
'getTraversableWithIndex - traverseWithIndex - ',
R.getTraversableWithIndex(OrdString).traverseWithIndex(TestApplicative1Test2a)(
fa6,
ia_b_function
)
)
console.log('getWitherable - compact - ', pipe(foa6, R.getWitherable(OrdString).compact))
console.log(
'getWitherable - filter - a_is_A_extends_refinement - ',
R.getWitherable(OrdString).filter(fa6, a_is_A_extends_refinement)
)
console.log(
'getWitherable - filter - a_is_bool_predicate - ',
R.getWitherable(OrdString).filter(fa6, a_is_bool_predicate)
)
console.log(
'getWitherable - filterMap - ',
R.getWitherable(OrdString).filterMap(fa6, a_ob_function)
)
console.log(
'getWitherable - foldMap - [2736 <= (123 + 456 + 789) * 2] - ',
R.getWitherable(OrdString).foldMap(TestMonoidTest2a)(fa6, a_a_function)
)
console.log('getWitherable - map - ', R.getWitherable(OrdString).map(fa6, a_b_function))
console.log(
'getWitherable - partition - a_is_A_extends_refinement - ',
R.getWitherable(OrdString).partition(fa6, a_is_A_extends_refinement)
)
console.log(
'getWitherable - partition - a_is_bool_predicate - ',
R.getWitherable(OrdString).partition(fa6, a_is_bool_predicate)
)
console.log(
'getWitherable - partitionMap - ',
R.getWitherable(OrdString).partitionMap(fa6, a_Ebx_function)
)
console.log(
'getWitherable - reduce - ',
R.getWitherable(OrdString).reduce(fa6, b, ba_b_function)
)
console.log(
'getWitherable - reduceRight - ',
R.getWitherable(OrdString).reduceRight(fa6, b, ab_b_function)
)
console.log('getWitherable - separate - ', pipe(fea6, R.getWitherable(OrdString).separate))
console.log(
'getWitherable - sequence - ',
pipe(fa6, R.getWitherable(OrdString).sequence(TestApplicative1Test2a))
)
console.log(
'getWitherable - traverse - ',
R.getWitherable(OrdString).traverse(TestApplicative1Test2a)(fa6, a_b_function)
)
console.log(
'getWitherable - wilt - ',
R.getWitherable(OrdString).wilt(TestApplicative1Test2a)(fa6, a_BEbx_function)
)
console.log(
'getWitherable - wither - ',
R.getWitherable(OrdString).wither(TestApplicative1Test2a)(fa6, a_bo_function)
)
console.log(
'getUnionSemigroup - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - ',
R.getUnionSemigroup(TestSemigroupTest2a).concat(fa6, fa3)
)
console.log(
'getUnionSemigroup - (fa6, fa3_k) - ',
R.getUnionSemigroup(TestSemigroupTest2a).concat(fa6, fa3_k)
)
console.log(
'getUnionMonoid - concat - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - ',
R.getUnionMonoid(TestSemigroupTest2a).concat(fa6, fa3)
)
console.log('getUnionMonoid - empty - ', R.getUnionMonoid(TestSemigroupTest2a).empty)
console.log(
'getIntersectionSemigroup - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - ',
R.getIntersectionSemigroup(TestSemigroupTest2a).concat(fa6, fa3)
)
console.log(
'getIntersectionSemigroup - (fa6, fa3_k) - ',
R.getIntersectionSemigroup(TestSemigroupTest2a).concat(fa6, fa3_k)
)
})
})
実行結果
a - { Test2: 123 }
b - { Test2: 'abc' }
fa3 - { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } }
fa6 - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
foa6 - {
key1: { _tag: 'Some', value: { Test2: 123 } },
key2: { _tag: 'None' },
key3: { _tag: 'Some', value: { Test2: 789 } },
key1_extends: { _tag: 'None' },
key2_extends: { _tag: 'Some', value: { Test2: 456, Test23: 'extends Test2<456>' } },
key3_extends: { _tag: 'Some', value: { Test2: 789, Test23: 'extends Test2<789>' } }
}
tka - [ 'key1', { Test2: 123 } ]
t2_tka - { Test2: [ 'key1', { Test2: 123 } ] }
t2_a - { Test2: { Test2: 123 } }
isEmpty - false
keys - [ 'key1', 'key2', 'key3' ]
collect - [
{ Test2: '(key1,123)' },
{ Test2: '(key2,456)' },
{ Test2: '(key3,789)' }
]
toReadonlyArray - [
[ 'key1', { Test2: 123 } ],
[ 'key2', { Test2: 456 } ],
[ 'key3', { Test2: 789 } ]
]
toUnfoldable - [ 'key1', { Test2: 123 } ]
upsertAt - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
'add key9': { Test2: 999 }
}
has - key1 - true
has - key999 - false
deleteAt - key1 - { key2: { Test2: 456 }, key3: { Test2: 789 } }
deleteAt - key999 - { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } }
updateAt - key1 - {
_tag: 'Some',
value: { key1: { Test2: 111 }, key2: { Test2: 456 }, key3: { Test2: 789 } }
}
updateAt - key999 - { _tag: 'None' }
modifyAt - key1 - {
_tag: 'Some',
value: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } }
}
modifyAt - key999 - { _tag: 'None' }
pop - key1 - {
_tag: 'Some',
value: [ { Test2: 123 }, { key2: [Object], key3: [Object] } ]
}
pop - key999 - { _tag: 'None' }
isSubrecord - fa3,fa3 - true
isSubrecord - fa3,fa2 - true
isSubrecord - fa2,fa3 - false
isSubrecord - fa3,fa2_111 - false
isSubrecord - fa3,fa3 - true
isSubrecord - fa3,fa2 - true
isSubrecord - fa2,fa3 - false
isSubrecord - fa3,fa2_111 - false
isSubrecord - key1 - { _tag: 'Some', value: { Test2: 123 } }
isSubrecord - key999 - { _tag: 'None' }
isSubrecord - key1 - { _tag: 'Some', value: { Test2: 123 } }
isSubrecord - key999 - { _tag: 'None' }
empty - {}
mapWithIndex - {
key1: { Test2: '(key1,123)' },
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' }
}
map - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' }
}
reduceWithIndex - { Test2: 'abc :: (key1,123) :: (key2,456) :: (key3,789)' }
foldMapWithIndex - [12]0[1368] - [12 = key1(4) + key2(4) + key3(4)] - [1368 = 123 + 456 + 789] { Test2: 1201368 }
reduceRightWithIndex - { Test2: 'abc :: (key3,789) :: (key2,456) :: (key1,123)' }
singleton - { key1: { Test2: 123 } }
traverseWithIndex - {
Test2: { key1: '(key1,123)', key2: '(key2,456)', key3: '(key3,789)' }
}
traverse - { Test2: { key1: '123', key2: '456', key3: '789' } }
sequence - { Test2: { key1: 123, key2: 456, key3: 789 } }
wither - { Test2: { key1: '123', key3: '789' } }
wilt - {
Test2: { left: { key2: [Array] }, right: { key1: '123', key3: '789' } }
}
partitionMapWithIndex - {
left: {
key1: [ 'key1', '<== key includes 1', 'ia_Ebx_function' ],
key2: [ '456', '<== even number is error', 'a_Ebx_function' ],
key1_extends: [ 'key1_extends', '<== key includes 1', 'ia_Ebx_function' ],
key2_extends: [ '456', '<== even number is error', 'a_Ebx_function' ]
},
right: { key3: '789', key3_extends: '789' }
}
partitionWithIndex - ia_refinement_A_extends - {
left: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } },
right: {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
partitionWithIndex - ia_predicate_a_is_bool - {
left: {
key2: { Test2: 456 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' }
},
right: {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
filterMapWithIndex - {
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' },
key2_extends: { Test2: '(key2_extends,456)' },
key3_extends: { Test2: '(key3_extends,789)' }
}
filterWithIndex - ia_refinement_A_extends - {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
filterWithIndex - ia_predicate_a_is_bool - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
fromFoldable - { key1: { Test2: 123 } }
fromFoldableMap - { a_tka_function: { Test2: 123 } }
toEntries - [
[ 'key1', { Test2: 123 } ],
[ 'key1_extends', { Test2: 123, Test23: 'extends Test2<123>' } ],
[ 'key2', { Test2: 456 } ],
[ 'key2_extends', { Test2: 456, Test23: 'extends Test2<456>' } ],
[ 'key3', { Test2: 789 } ],
[ 'key3_extends', { Test2: 789, Test23: 'extends Test2<789>' } ]
]
fromEntries - { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } }
every - false
some - true
elem - fa6,a - true
elem - fa6,a111 - false
elem - fa6,a - true
elem - fa6,a111 - false
union - (fa6, fa2_111) => [234 = 123 + 111], [912 = 456 + 456] - {
key1: { Test2: 234 },
key2: { Test2: 912 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
union - (fa6, fa3_k) - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' },
k1: { Test2: 123 },
k2: { Test2: 456 },
k3: { Test2: 789 }
}
intersection - (fa6, fa2_111) => [234 = 123 + 111], [912 = 456 + 456] - { key1: { Test2: 234 }, key2: { Test2: 912 } }
intersection - (fa6, fa3_k) - {}
difference - (fa6, fa2_111) - {
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
difference - (fa6, fa3_k) - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' },
k1: { Test2: 123 },
k2: { Test2: 456 },
k3: { Test2: 789 }
}
filter - a_is_A_extends_refinement - {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
filter - a_is_bool_predicate - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
filterMap - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
partition - a_is_A_extends_refinement - {
left: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } },
right: {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
partition - a_is_bool_predicate - {
left: {
key2: { Test2: 456 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' }
},
right: {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
partitionMap - {
left: {
key2: [ '456', '<== even number is error', 'a_Ebx_function' ],
key2_extends: [ '456', '<== even number is error', 'a_Ebx_function' ]
},
right: {
key1: '123',
key3: '789',
key1_extends: '123',
key3_extends: '789'
}
}
reduce - { Test2: 'abc :: 123 :: 456 :: 789' }
foldMap - [1368 = 123 + 456 + 789] - { Test2: 1368 }
reduceRight - { Test2: 'abc :: 789 :: 456 :: 123' }
compact - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
separate - {
left: {
key1: [ '123', 'key1 includes 1', 'fea6[key1]' ],
key2: [ '456', '456 is even number', 'fea6[key2]' ],
key2_extends: [
'456',
'key1 includes 2',
'fea6[key2_extends]',
'extends Test2<456>'
],
key3_extends: [
'789',
'789 above 500',
'fea6[key3_extends]',
'extends Test2<789>'
]
},
right: {
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
getShow - { "key1": 123, "key1_extends": 123, "key2": 456, "key2_extends": 456, "key3": 789, "key3_extends": 789 }
getEq - (fa6, fa3) - false
getEq - (fa6, fa6_ng) - true
getEq - (fa6, fa6) - true
getMonoid - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - {
key1: { Test2: 246 },
key2: { Test2: 912 },
key3: { Test2: 1578 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getMonoid - (fa6, fa3_k) - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' },
k1: { Test2: 123 },
k2: { Test2: 456 },
k3: { Test2: 789 }
}
map - (fa6, a_a_function) - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123 },
key2_extends: { Test2: 456 },
key3_extends: { Test2: 789 }
}
map - (fa6, a_b_function) - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
flap - (fa6, fa_b_function_object) - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
flap - (fa_extends_6, fa_extends_b_function_object) - {
key1: { Test2: 'b is null' },
key2: { Test2: 'b is null' },
key3: { Test2: 'b is null' },
key1_extends: { Test2: '123-extends Test2<123>' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
FunctorWithIndex - map - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
FunctorWithIndex - mapWithIndex - {
key1: { Test2: '(key1,123)' },
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' },
key1_extends: { Test2: '(key1_extends,123)' },
key2_extends: { Test2: '(key2_extends,456)' },
key3_extends: { Test2: '(key3_extends,789)' }
}
getFoldable - foldMap - [2736 <= (123 + 456 + 789) * 2] - { Test2: 2736 }
getFoldable - reduce - { Test2: 'abc :: 123 :: 123 :: 456 :: 456 :: 789 :: 789' }
getFoldable - reduceRight - { Test2: 'abc :: 789 :: 789 :: 456 :: 456 :: 123 :: 123' }
getFoldableWithIndex - foldMapWithIndex - [48]0[2736] - [48 = key1(4) + key2(4) + key3(4) + key1_extends(12) + key2_extends(12) + key3_extends(12)] - [2736 <= (123 + 456 + 789) * 2] - { Test2: 4802736 }
getFoldableWithIndex - reduceWithIndex - {
Test2: 'abc :: (key1,123) :: (key1_extends,123) :: (key2,456) :: (key2_extends,456) :: (key3,789) :: (key3_extends,789)'
}
getFoldableWithIndex - reduceRightWithIndex - {
Test2: 'abc :: (key3_extends,789) :: (key3,789) :: (key2_extends,456) :: (key2,456) :: (key1_extends,123) :: (key1,123)'
}
Compactable - compact - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
Compactable - separate - {
left: {
key1: [ '123', 'key1 includes 1', 'fea6[key1]' ],
key2: [ '456', '456 is even number', 'fea6[key2]' ],
key2_extends: [
'456',
'key1 includes 2',
'fea6[key2_extends]',
'extends Test2<456>'
],
key3_extends: [
'789',
'789 above 500',
'fea6[key3_extends]',
'extends Test2<789>'
]
},
right: {
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
Filterable - compact - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
Filterable - filter - a_is_A_extends_refinement - {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
Filterable - filter - a_is_bool_predicate - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
Filterable - filterMap - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
Filterable - map - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
Filterable - partition - a_is_A_extends_refinement - {
left: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } },
right: {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
Filterable - partition - a_is_bool_predicate - {
left: {
key2: { Test2: 456 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' }
},
right: {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
Filterable - partitionMap - {
left: {
key2: [ '456', '<== even number is error', 'a_Ebx_function' ],
key2_extends: [ '456', '<== even number is error', 'a_Ebx_function' ]
},
right: {
key1: '123',
key3: '789',
key1_extends: '123',
key3_extends: '789'
}
}
Filterable - separate - {
left: {
key1: [ '123', 'key1 includes 1', 'fea6[key1]' ],
key2: [ '456', '456 is even number', 'fea6[key2]' ],
key2_extends: [
'456',
'key1 includes 2',
'fea6[key2_extends]',
'extends Test2<456>'
],
key3_extends: [
'789',
'789 above 500',
'fea6[key3_extends]',
'extends Test2<789>'
]
},
right: {
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
FilterableWithIndex - filterMapWithIndex - {
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' },
key2_extends: { Test2: '(key2_extends,456)' },
key3_extends: { Test2: '(key3_extends,789)' }
}
FilterableWithIndex - filterWithIndex - ia_refinement_A_extends - {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
FilterableWithIndex - filterWithIndex - ia_predicate_a_is_bool - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
FilterableWithIndex - mapWithIndex - {
key1: { Test2: '(key1,123)' },
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' },
key1_extends: { Test2: '(key1_extends,123)' },
key2_extends: { Test2: '(key2_extends,456)' },
key3_extends: { Test2: '(key3_extends,789)' }
}
FilterableWithIndex - partitionMapWithIndex - {
left: {
key1: [ 'key1', '<== key includes 1', 'ia_Ebx_function' ],
key2: [ '456', '<== even number is error', 'a_Ebx_function' ],
key1_extends: [ 'key1_extends', '<== key includes 1', 'ia_Ebx_function' ],
key2_extends: [ '456', '<== even number is error', 'a_Ebx_function' ]
},
right: { key3: '789', key3_extends: '789' }
}
FilterableWithIndex - partitionWithIndex - ia_refinement_A_extends - {
left: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } },
right: {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
FilterableWithIndex - partitionWithIndex - ia_predicate_a_is_bool - {
left: {
key2: { Test2: 456 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' }
},
right: {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
getTraversable - foldMap - [2736 <= (123 + 456 + 789) * 2] - { Test2: 2736 }
getTraversable - map - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
getTraversable - reduce - { Test2: 'abc :: 123 :: 123 :: 456 :: 456 :: 789 :: 789' }
getTraversable - reduceRight - { Test2: 'abc :: 789 :: 789 :: 456 :: 456 :: 123 :: 123' }
getTraversable - sequence - {
Test2: {
key1: 123,
key1_extends: 123,
key2: 456,
key2_extends: 456,
key3: 789,
key3_extends: 789
}
}
getTraversable - traverse - {
Test2: {
key1: '123',
key1_extends: '123',
key2: '456',
key2_extends: '456',
key3: '789',
key3_extends: '789'
}
}
getTraversableWithIndex - foldMapWithIndex - [48]0[2736] - [48 = key1(4) + key2(4) + key3(4) + key1_extends(12) + key2_extends(12) + key3_extends(12)] - [2736 <= (123 + 456 + 789) * 2] - { Test2: 4802736 }
getTraversableWithIndex - mapWithIndex - {
key1: { Test2: '(key1,123)' },
key2: { Test2: '(key2,456)' },
key3: { Test2: '(key3,789)' },
key1_extends: { Test2: '(key1_extends,123)' },
key2_extends: { Test2: '(key2_extends,456)' },
key3_extends: { Test2: '(key3_extends,789)' }
}
getTraversableWithIndex - reduceRightWithIndex - {
Test2: 'abc :: (key3_extends,789) :: (key3,789) :: (key2_extends,456) :: (key2,456) :: (key1_extends,123) :: (key1,123)'
}
getTraversableWithIndex - reduceWithIndex - {
Test2: 'abc :: (key1,123) :: (key1_extends,123) :: (key2,456) :: (key2_extends,456) :: (key3,789) :: (key3_extends,789)'
}
getTraversableWithIndex - traverseWithIndex - {
Test2: {
key1: '(key1,123)',
key1_extends: '(key1_extends,123)',
key2: '(key2,456)',
key2_extends: '(key2_extends,456)',
key3: '(key3,789)',
key3_extends: '(key3_extends,789)'
}
}
getWitherable - compact - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getWitherable - filter - a_is_A_extends_refinement - {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getWitherable - filter - a_is_bool_predicate - {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getWitherable - filterMap - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
getWitherable - foldMap - [2736 <= (123 + 456 + 789) * 2] - { Test2: 2736 }
getWitherable - map - {
key1: { Test2: '123' },
key2: { Test2: '456' },
key3: { Test2: '789' },
key1_extends: { Test2: '123' },
key2_extends: { Test2: '456' },
key3_extends: { Test2: '789' }
}
getWitherable - partition - a_is_A_extends_refinement - {
left: { key1: { Test2: 123 }, key2: { Test2: 456 }, key3: { Test2: 789 } },
right: {
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
getWitherable - partition - a_is_bool_predicate - {
left: {
key2: { Test2: 456 },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' }
},
right: {
key1: { Test2: 123 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
}
getWitherable - partitionMap - {
left: {
key2: [ '456', '<== even number is error', 'a_Ebx_function' ],
key2_extends: [ '456', '<== even number is error', 'a_Ebx_function' ]
},
right: {
key1: '123',
key3: '789',
key1_extends: '123',
key3_extends: '789'
}
}
getWitherable - reduce - { Test2: 'abc :: 123 :: 123 :: 456 :: 456 :: 789 :: 789' }
getWitherable - reduceRight - { Test2: 'abc :: 789 :: 789 :: 456 :: 456 :: 123 :: 123' }
getWitherable - separate - {
left: {
key1: [ '123', 'key1 includes 1', 'fea6[key1]' ],
key2: [ '456', '456 is even number', 'fea6[key2]' ],
key2_extends: [
'456',
'key1 includes 2',
'fea6[key2_extends]',
'extends Test2<456>'
],
key3_extends: [
'789',
'789 above 500',
'fea6[key3_extends]',
'extends Test2<789>'
]
},
right: {
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' }
}
}
getWitherable - sequence - {
Test2: {
key1: 123,
key1_extends: 123,
key2: 456,
key2_extends: 456,
key3: 789,
key3_extends: 789
}
}
getWitherable - traverse - {
Test2: {
key1: '123',
key1_extends: '123',
key2: '456',
key2_extends: '456',
key3: '789',
key3_extends: '789'
}
}
getWitherable - wilt - {
Test2: {
left: { key2: [Array], key2_extends: [Array] },
right: {
key1: '123',
key1_extends: '123',
key3: '789',
key3_extends: '789'
}
}
}
getWitherable - wither - {
Test2: {
key1: '123',
key1_extends: '123',
key3: '789',
key3_extends: '789'
}
}
getUnionSemigroup - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - {
key1: { Test2: 246 },
key2: { Test2: 912 },
key3: { Test2: 1578 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getUnionSemigroup - (fa6, fa3_k) - {
key1: { Test2: 123 },
key2: { Test2: 456 },
key3: { Test2: 789 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' },
k1: { Test2: 123 },
k2: { Test2: 456 },
k3: { Test2: 789 }
}
getUnionMonoid - concat - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - {
key1: { Test2: 246 },
key2: { Test2: 912 },
key3: { Test2: 1578 },
key1_extends: { Test2: 123, Test23: 'extends Test2<123>' },
key2_extends: { Test2: 456, Test23: 'extends Test2<456>' },
key3_extends: { Test2: 789, Test23: 'extends Test2<789>' }
}
getUnionMonoid - empty - {}
getIntersectionSemigroup - (fa6, fa3) => [246 = 123 + 123], [912 = 456 + 456], [1578 = 789 + 789] - { key1: { Test2: 246 }, key2: { Test2: 912 }, key3: { Test2: 1578 } }
getIntersectionSemigroup - (fa6, fa3_k) - {}