Search results

The Apply class provides the (<*>) which is used to apply a function to an argument under a type constructor.

Apply can be used to lift functions of two or more arguments to work on values wrapped with the type constructor f. It might also be understood in terms of the lift2 function:

lift2 :: forall f a b c. Apply f => (a -> b -> c) -> f a -> f b -> f c
lift2 f a b = f <$> a <*> b

(<*>) is recovered from lift2 as lift2 ($). That is, (<*>) lifts the function application operator ($) to arguments wrapped with the type constructor f.

Put differently...

foo =
  functionTakingNArguments <$> computationProducingArg1
                           <*> computationProducingArg2
                           <*> ...
                           <*> computationProducingArgN

Instances must satisfy the following law in addition to the Functor laws:

  • Associative composition: (<<<) <$> f <*> g <*> h = f <*> (g <*> h)

Formally, Apply represents a strong lax semi-monoidal endofunctor.

apply :: forall f a b. Apply f => f (a -> b) -> f a -> f b
apply :: forall a b. (a -> b) -> a -> b

Applies a function to an argument. This is primarily used as the operator ($) which allows parentheses to be omitted in some cases, or as a natural way to apply a chain of composed functions to a value.

Polymorphic Type application

For example...

APPLY Maybe Int == Maybe $ Int == Maybe Int
apply :: forall m a b x y z. IxApply m => m x y (a -> b) -> m y z a -> m x z b
apply :: App -> Application -> Effect Unit

Apply App actions to existent Express.js application

apply :: forall c f v1 v0. HasApply c f => ObjectOf c v0 => ObjectOf c v1 => ObjectOf c (c v0 v1) => f (c v0 v1) -> c (f v0) (f v1)
apply :: forall c f v1 v0. HasApply c f => ObjectOf c v0 => ObjectOf c v1 => ObjectOf c (c v0 v1) => f (c v0 v1) -> f v0 -> f v1
apply :: forall b a. NotJSPromise a => NotJSPromise b => PromiseSpec (a -> b) -> PromiseSpec a -> PromiseSpec b

apply a function to a value inside promise specs

apply :: forall b a. Jet (Atomic (a -> b)) -> Jet (Atomic a) -> Jet (Atomic b)

Combine two Atomic values in an applicative style.

apply :: forall b a. Iso a b -> a -> Maybe b
apply :: forall e. Server e -> Server -> RestifyM e Unit

Apply Server actions to a Restify server.

apply :: forall r. Array (Setting UnresolvedValue) -> Run (CHILD_PROCESS + ENVIRONMENT + r) Unit

Applies the specified settings to the environment.

apply :: forall b a f. f -> Array a -> b
apply :: forall b a m r. Format m r (a -> b) -> a -> Format m r b

Apply the first argument of the formatter, without unwrapping it to a plain ol' function.

apply :: forall f b a. ProductFunctor f => f a -> f b -> f (Tuple a b)
apply :: forall t1 f x y a b. Semigroupal Function t1 Tuple Tuple f => Functor (f (t1 x y)) => f x (a -> b) -> f y a -> f (t1 x y) b
apply :: forall f a b. Semigroupal Function Tuple Tuple f => Functor f => f (a -> b) -> f a -> f b
apply :: forall t1 t2 f a1 b1 a2 b2 a b. Semigroupal Function t1 t2 Tuple Tuple f => Functor (f (t1 a1 b1) (t2 a2 b2)) => f a1 a2 (a -> b) -> f b1 b2 a -> f (t1 a1 b1) (t2 a2 b2) b
apply :: forall a c b. HasApply a => a (b -> c) -> a b -> a c
apply :: forall f m a b. Parallel f m => m (a -> b) -> m a -> m b
apply :: forall a b f. Codensity f (a -> b) -> Codensity f a -> Codensity f b
apply :: forall a b f g. (g ~> f) -> Ran f g (a -> b) -> Ran f g a -> Ran f g b
apply :: forall e. Router e -> Router -> RestifyM e Unit

Apply Router actions to a Restify router.

apply :: forall r dom img. Expr r dom => Expr r img => Z3Function r dom img -> dom -> img
apply :: forall r dom img. Fn2 (Z3Function r dom img) dom img
applyN :: forall a. (a -> a) -> Int -> a -> a

applyN f n applies the function f to its argument n times.

If n is less than or equal to 0, the function is not applied.

applyN (_ + 1) 10 0 == 10
apply_ :: forall b a s w r. Semigroup w => RWS r w s (a -> b) -> RWS r w s a -> RWS r w s b
applyR :: forall b a r. Reader r (a -> b) -> Reader r a -> Reader r b
applyS :: forall b a. Behavior (a -> b) -> Stream a -> Stream b

This function is similar to apply for behaviors except the last argument is a stream instead of a behaviors. Whenever the stream has an occurrence the function at the behavior is applied to the value of the occurrence.

This function has an operator alias <~>. The operator is intended to work in tandem with <$> and <*>. As an example, assume that f3 is a function of three arguments, that b1 and b2 are two behaviors, and that s is a stream.` Then the function can be applied to the two behaviors and the stream in the following way.

f3 <$> b1 <*> b2 <~> s

With the above code, whenever s has an occurrence the value of b1, b2, and the value of the occurrence will be applied to f3 and its return value will be the value of the occurrence in the resulting stream.

Semantically.

applyS b s = map (\{time, a} -> {time, a: (b time) a}) s
applyS :: forall b a s. State s (a -> b) -> State s a -> State s b
applyW :: forall b a w. Semigroup w => Writer w (a -> b) -> Writer w a -> Writer w b
apply2 :: forall r dom1 dom2 img. Expr r dom1 => Expr r dom2 => Expr r img => Z3Function2 r dom1 dom2 img -> dom1 -> dom2 -> img
apply2 :: forall r dom1 dom2 img. Fn3 (Z3Function2 r dom1 dom2 img) dom1 dom2 img
applyS :: forall @f @a @b. Select f => f (a -> b) -> f a -> f b

apply implemented in terms of select

applyOp :: forall event a b. Applicative event => event a -> event (a -> b) -> event b
applyTo :: forall f this a b. f -> this -> a -> b

Apply a function to a this object with the given arguments

applyTo :: forall res list row a. RowToList row list => RFold (ApplyS a) list row (Builder (Record ()) (Record res)) => a -> Record row -> Record res
applyEnd :: forall a. WrapRule a -> Doc a
applyDir :: forall a dir args. IsSymbol dir => Proxy dir -> args -> a -> ApplyDirective dir args a

Apply a directive

applyPoly :: forall a. Eq a => Semiring a => Polynomial (Square a) -> Square a -> Square a

Polynomial application

applyWrap :: forall srf fm fs msg sta a. DataUI srf fm fs msg sta a -> DataUI srf fm fs (fm msg) (fs sta) a
applyCons :: forall f a. Apply f => f a -> f (Array a) -> f (Array a)
applyImpl :: forall a b. AffList (a -> b) -> AffList a -> AffList b
applyPick :: forall input err a. input -> PickE input err a -> ValidatedE err a

Task.mapN -> liftN

applyFirst :: forall a b f. Apply f => f a -> f b -> f a

Combine two effectful actions, keeping only the result of the first.

The Apply instance allows functions contained within a Just to transform a value contained within a Just using the apply operator:

Just f <*> Just x == Just (f x)

Nothing values are left untouched:

Just f <*> Nothing == Nothing
Nothing <*> Just x == Nothing

Combining Functor's <$> with Apply's <*> can be used transform a pure function to take Maybe-typed arguments so f :: a -> b -> c becomes f :: Maybe a -> Maybe b -> Maybe c:

f <$> Just x <*> Just y == Just (f x y)

The Nothing-preserving behaviour of both operators means the result of an expression like the above but where any one of the values is Nothing means the whole result becomes Nothing also:

f <$> Nothing <*> Just y == Nothing
f <$> Just x <*> Nothing == Nothing
f <$> Nothing <*> Nothing == Nothing

The Apply instance allows functions to transform the contents of a Tuple with the <*> operator whenever there is a Semigroup instance for the fst component, so:

(Tuple a1 f) <*> (Tuple a2 x) == Tuple (a1 <> a2) (f x)
applyMaybe :: forall f a b. Apply f => Compactable f => f (a -> Maybe b) -> f a -> f b
applyState :: forall m r s a. MonadEffect m => Refer s r => State s a -> r -> m a
applyScale :: ContinuousScale -> Number -> Number

Apply a scale to a domain value, producing a range value

scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
applyScale scale 50.0  -- Returns 250.0
applyThird :: forall x y z a. (y -> z -> x -> a) -> x -> y -> z -> a

\f x y z -> f y z x

applyFirst :: forall v1 v0 f c. HasApply c f => HasConst c => HasMap c f => ObjectOf c v0 => ObjectOf c v1 => ObjectOf c (f v0) => ObjectOf c (f v1) => ObjectOf c (c v1 v0) => ObjectOf c (f (c v1 v0)) => ObjectOf c (c v0 (c v1 v0)) => ObjectOf c (c (f v1) (f v0)) => ObjectOf c (c (f v1) (f v0)) => ObjectOf c (f (c v0 (c v1 v0))) => ObjectOf c (c (f v0) (f (c v1 v0))) => Restrictable Function c => Slackable c => f v0 -> c (f v1) (f v0)
applyFirst :: forall v1 v0 f c. HasApply c f => HasConst c => HasMap c f => ObjectOf c v0 => ObjectOf c v1 => ObjectOf c (c v1 v0) => f v0 -> f v1 -> f v0
applyForce :: ForceHandle -> Number -> Effect Unit

Apply a single force

applyForce :: ForceHandle -> Number -> Effect Unit

Apply a single force This mutates vx/vy on the nodes the force was initialized with

applyRules :: forall node. Array (NodeRule node) -> Array node -> Array node

Apply rules to an array of nodes (first matching rule wins).

For each node, finds the first rule whose selector matches, then applies that rule's transform. If no rule matches, the node is returned unchanged.

This is CSS-like cascade semantics - rule order matters.

applyRules :: forall node. Array (NodeRule node) -> Array node -> Array node

Apply rules to nodes (first matching rule wins) - creates new array

applySetup :: forall row linkRow. Setup (SimulationNode row) -> Simulation row linkRow -> Effect Unit

Apply a setup to a simulation.

This is idempotent - calling with the same setup does minimal work:

  • Forces in setup but not simulation: create and add
  • Forces in simulation but not setup: remove

After applying, forces are re-initialized with current nodes.

applySetup :: forall row linkRow. Setup (SimulationNode row) -> Simulation row linkRow -> Effect Unit

Apply a setup to a simulation.

This is idempotent - calling with the same setup does minimal work:

  • Forces in setup but not simulation: create and add
  • Forces in simulation but not setup: remove

After applying, forces are re-initialized with current nodes.

Example:

-- Initial setup
applySetup mySetup sim

-- Later: update setup (just call again)
applySetup (mySetup # removeForce "charge") sim
applySetup :: forall r. Setup (SimulationNode r) -> WASMSim r -> Effect Unit

Apply a Setup to a WASM simulation.

Maps declarative force configuration to WASM kernel calls. This is idempotent - can be called repeatedly with different setups.

Limitations vs D3:

  • Only one force of each type (first wins if multiple specified)
  • Dynamic values fall back to static (with warning)
  • Filters are ignored (with warning)
  • ForceRadial is not supported (warning logged)
applyStart :: forall a. WrapRule a -> Doc a