Hi, I just published a helper library for folding( by means of composition) 
a list of functions.

powet/funfolding <https://github.com/powet/elm-funfolding>


There are many use-cases but please find below an example use-case for 
dynamically constructing filter functions:

 imagine you want to filter a list of integers [-100..100] using the 
following predicates:

   - (\x->x/=0)
   - (\x->x>(-20))
   - (\x->x<20)
   - (\x->(rem x 10) == 0)

The expected result is : [-10,10]

We foldl all the predicates using the (&&) operator, the outcome is a 
single predicate function that we use in List.filter 
<http://package.elm-lang.org/packages/elm-lang/core/latest/List#filter>

The folding function that we use is defined by:

andN : List (a->Bool) -> a -> BoolandN =
  foldlFun (&&) False

this function can be used the following way:

test "Compare with 4 predicates" <|
    \() ->
     let           
       fun = andN [ (\x->x/=0)
                  , (\x->x>(-20))
                  , (\x->x<20)
                  , (\x->(rem x 10) == 0)
                  ]
       result = List.filter fun [-100..100]
       expected = [-10,10]
     in
       (Expect.equal result expected)

Thanks in advance for the community feedback.


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to