query
On this page

mirrorFunctionArgs

lib.trivial.mirrorFunctionArgs

Docs pulled from | This Revision | 8 minutes ago


mirrorFunctionArgs f g creates a new function g' with the same behavior as g (g' x == g x) but its function arguments mirroring f (lib.functionArgs g' == lib.functionArgs f).

Inputs

f

Function to provide the argument metadata

g

Function to set the argument metadata to

Type

mirrorFunctionArgs :: (a -> b) -> (a -> c) -> (a -> c)

Examples

lib.trivial.mirrorFunctionArgs usage example

addab = {a, b}: a + b
addab { a = 2; b = 4; }
=> 6
lib.functionArgs addab
=> { a = false; b = false; }
addab1 = attrs: addab attrs + 1
addab1 { a = 2; b = 4; }
=> 7
lib.functionArgs addab1
=> { }
addab1' = lib.mirrorFunctionArgs addab addab1
addab1' { a = 2; b = 4; }
=> 7
lib.functionArgs addab1'
=> { a = false; b = false; }

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

mirrorFunctionArgs =
    f:
    let
      fArgs = functionArgs f;
    in
    g:
    setFunctionArgs g fArgs;