Skip to main content Link Search Menu Expand Document (external link)

Function overview

A simple extension to the Effect Function module


Table of contents


Constants

proto

The Function.prototype

Signature

export declare const proto: MTypes.NonPrimitive

Utils

applyAsThis

Applies no-argument self to o

Signature

export declare const applyAsThis: (o: MTypes.NonPrimitive) => <A>(self: Function.LazyArg<A>) => A

clone

Returns a copy of self

Signature

export declare const clone: <This, Args extends ReadonlyArray<unknown>, R>(
  self: (this: This, ...args: Args) => R
) => (this: This, ...args: Args) => R

constEmptyString

Returns a lazy empty string

Signature

export declare const constEmptyString: Function.LazyArg<string>

execute

Calls self without any argument

Signature

export declare const execute: <A>(self: Function.LazyArg<A>) => A

fIfTrue

Applies function f if condition is true

Signature

export declare const fIfTrue: <A>({
  condition,
  f
}: {
  readonly condition: boolean
  readonly f: (a: NoInfer<A>) => NoInfer<A>
}) => (a: A) => A

flipDual

Flips a dual function by targetting the non-curried overload. If the dual function takes type parameters, most of the time you need to pass them. For instance: MFunction.flipDual(Array.get)(targetValues)

Signature

export declare const flipDual: <First, Others extends ReadonlyArray<unknown>, R>(
  self: (first: First, ...others: Others) => R
) => (first: First) => (...others: Others) => R

name

Returns the name of a function

Signature

export declare const name: (f: MTypes.AnyFunction) => string

once

Function to memoize a function that takes no argument. Useful to initialize a time-consuming constant only when it is used (not at startup) privided it is used more than once. Otherwise, this function is useless.

Instead of exporting the result of calling this function (which would then take time at startup), create a memoized version of the function and call it in the code when necessary.

Note that any unused constant will be tree-shaken, so do not use this function if startup time is not an issue.

Signature

export declare const once: <A>(f: Function.LazyArg<A>) => Function.LazyArg<A>

Example

import { MFunction } from "@parischap/effect-lib"

const complexFoo = () => 1
const memoized = MFunction.once(complexFoo)

export function foo1() {
  return memoized() + 1
}

export function foo2() {
  return memoized() + 2
}

parameterNumber

Returns the expected number of parameters of a function

Signature

export declare const parameterNumber: (f: MTypes.AnyFunction) => number

strictEquals

Strict equality predicate

Signature

export declare const strictEquals: <A>(that: NoInfer<A>) => Predicate.Predicate<A>