++ed by:

1 non-PAUSE user.

Toshio Ito


Data::Focus::Applicative - applicative functor spec for Data::Focus


This interface is experimental for now. You should not use them directly.

This class specifies the common interface for all applicative functors used in Data::Focus distribution.

All applicative functors must inherit Data::Focus::Applicative, and implement the following methods.


$f_result = $class->build($builder, @f_parts)

Build the $f_result with $builder and @f_parts.

@f_parts are zero or more Data::Focus::Applicative objects. They must be instances of the $class. build() method is the only interface where you can access raw data wrapped inside @f_parts.

$builder is a code-ref, which may be called zero or more times

    $result = $builder->(@parts)

where @parts are the data inside @f_parts applicative functors.

Return value $f_result is an object of the $class. It wraps the $result.

$f_result = $class->pure($result)

Wraps $result with an wrapper object of $class. This is equivalent to $class->build(sub { $result }).

$part_mapper = $class->create_part_mapper($updater)

Internal use only.

Create the finest $part_mapper for Data::Focus::Lens.

$updater is a code-ref. This code-ref is supposed to modify the finest part and return the result. Subclasses may or may not use $updater to create $part_mapper.


In pseudo-Haskell, build() method is equivalent to

    build :: Applicative f => (b -> b -> ... -> t) -> [f b] -> f t
    build builder f_parts =
      case f_parts of
        [] -> pure builder  -- (builder :: t) in this case
        (p:ps) -> builder <$> p <*> (ps !! 0) <*> (ps !! 1) ...

I think this is the only pattern where applicative functors are used in Lens implementations.

The signature of create_part_mapper() method is

    create_part_mapper :: Applicative f => (a -> b) -> (a -> f b)


Toshio Ito, <toshioito at cpan.org>