import { isPlainObject, isFunction } from '../../internal/base' import { Data, Mutation, isAtomLike, DEFAULT_MUTATION_OPTIONS } from '../atoms' import { pipeAtom, binaryTweenPipeAtom } from '../helpers' import type { MutatorOriginalTransformationUnion } from '../particles' import type { MutationOptions, AtomLikeOfOutput } from '../atoms' // S -> Single, M -> Multi /****************************************************************************************************** * * SS Tache * ******************************************************************************************************/ /** * */ export type SSTache

= (source: AtomLikeOfOutput

) => Data /** * @param transformation * @param options same as MutationOptions * @return { SSTache } SSTache :: `(source) => Data` */ export const createSSTache = ( transformation: MutatorOriginalTransformationUnion, options: MutationOptions = DEFAULT_MUTATION_OPTIONS ): SSTache => { if (!isFunction(transformation)) { throw (new TypeError('"transformation" is expected to be type of "Function".')) } if (!isPlainObject(options)) { throw (new TypeError('"options" is expected to be type of "PlainObject".')) } const preparedOptions = { ...DEFAULT_MUTATION_OPTIONS, ...options } /** * @param source * @return { Data } Data */ return source => { if (!isAtomLike(source)) { throw (new TypeError('"target" is expected to be type of "AtomLike".')) } const mutation = Mutation.ofLift(transformation, preparedOptions) const outputD = Data.empty() pipeAtom(mutation, outputD) binaryTweenPipeAtom(source, mutation) return outputD } }