[Compose] 16. Apply multiple functors as arguments to a function (applicatives)

Source: Internet
Author: User

We find a couple of DOM nodes that may or may not be exist and run a calculation on the page height using applicatives.

For example we want to get the main content sections size by reduce the height of the header and footer, nomarlly we'll do Li Ke this:

1. Get the header height

2. Get the footer height

3. Use the screen height-header-footer.

Const   $ = selector =ten})const getscreensize = (screen, header, Footer) = Screen-(header + footer); $ ('header'). Chain (Header =      $ ('footer'). Map (footer =         getscreensize (  ,header, footer    )))

This happens in sequential, we can use Currey function to improve the code:

Const getscreensize = Screen =  /Header = Footer = Screen  -(header + footer);
either.of (getscreensize)    . AP ($ ('header'))    . AP ($ ('  footer'))

Or We can use:

const liftA2 = (f, FX, FY) =  Fx.map (f). AP (FY)
Const res = liftA2 (Getscreensize (), $ ('header'), $ ('footer '))

[Compose] 16. Apply multiple functors as arguments to a function (applicatives)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.