Beispiel #1
0
def permuteFloats(lst):
    startList = \
        pipe(lst,
        [
            F(List.map)(
                Basics.toFloat
            )
        ])


    newElements = \
        pipe(startList,
        [
            List.sort,
            F(List.map)(
                lambda n:
                    (n + 0.5)

            ),
            lambda items:
                List.cons(0.5, items)

        ])

    return pipe(newElements, [
        F(List.map)(List.singleton),
        F(List.map)(lambda x: List.append(startList, x))
    ])
Beispiel #2
0
def ranks(lst):
    return \
        pipe(lst,
        [
            F(List.indexedMap)(
                Tuple.pair
            ),
            F(List.sortBy)(
                Tuple.second
            ),
            F(List.map)(
                Tuple.first
            ),
            F(List.indexedMap)(
                Tuple.pair
            ),
            F(List.sortBy)(
                Tuple.second
            ),
            F(List.map)(
                Tuple.first
            ),
            F(List.map)(
                lambda n:
                    (n + 1)

            )
        ])
Beispiel #3
0
def map5(lst):
    return \
        pipe(lst,
        [
            F(List.map5)(
                lambda a, b, c, d, e:
                    F(Tuple.pair)(
                        a,
                        F(Tuple.pair)(
                            b,
                            F(Tuple.pair)(
                                c,
                                F(Tuple.pair)(
                                    d,
                                    e
                                )
                            )
                        )
                    )
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ]),
                List.toElm([ 1, 2, 3, 4, 5 ]),
                List.toElm([ 33, 97, 103 ])
            )
        ])
Beispiel #4
0
def map2(lst):
    return \
        pipe(lst,
        [
            F(List.map2)(
                List.range,
                List.toElm([ 1, 2, 3 ])
            )
        ])
Beispiel #5
0
def foldr(lst):
    return \
        pipe(lst,
        [
            F(List.foldr)(
                List.cons,
                List.toElm([  ])
            )
        ])
Beispiel #6
0
def filter(lst):
    return \
        pipe(lst,
        [
            F(List.filter)(
                lambda x:
                    (x == 4)

            )
        ])
Beispiel #7
0
def map2Pythag(lst):
    return \
        pipe(lst,
        [
            F(List.map2)(
                lambda x, y:
                    ((x * x) + (y * y))
                ,
                List.toElm([ 3, 5, 7 ])
            )
        ])
Beispiel #8
0
def map3(lst):
    return \
        pipe(lst,
        [
            F(List.map3)(
                lambda x, y, z:
                    ((x * 100) + ((y * 10) + z))
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ])
            )
        ])
Beispiel #9
0
def factorial2(n):
    return \
        pipe(F(List.range)(
            1,
            n
        ),
        [
            F(List.foldl)(
                lambda a, b: a * b,
                1
            )
        ])
Beispiel #10
0
def map4(lst):
    return \
        pipe(lst,
        [
            F(List.map4)(
                lambda a, b, c, d:
                    ((a + b) * (c + d))
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ]),
                List.toElm([ 1, 2 ])
            )
        ])
Beispiel #11
0
def unzip(lst):
    return \
        pipe(lst,
        [
            F(List.map)(
                lambda x:
                    F(Tuple.pair)(
                        x,
                        (x * 3)
                    )

            ),
            List.unzip
        ])
Beispiel #12
0
def ranks(lst):
    """
    This returns a list of integers representing the
    "each" element in the input list.  The rank of 0
    is for the "lowest" element in the list, and so on.
    """
    return pipe(lst, [
        (List.indexedMap)(Tuple.pair),
        (List.sortBy)(Tuple.second),
        (List.map)(Tuple.first),
        (List.indexedMap)(Tuple.pair),
        (List.sortBy)(Tuple.second),
        (List.map)(Tuple.first),
    ])