jmpavlick/q/1.1.0

S

The "S" is for "spread".

As in, "spread" some argument with n maps over an n-ary function.

S is actually kind of cool, and some people may find it genuinely useful. Look at this:

type alias Permission =
    { canLogIn : Bool
    , canSendInvite : Bool
    , canReadActivityLogs : Bool
    , canTeleport : Bool
    }


isAdmin : Permission -> Bool
isAdmin =
    S.s4 (\a b c d -> List.all [ a, b, c ] || d)
        .canLogIn
        .canSendInvite
        .canReadActivityLogs
        .canTeleport

Maybe, that is not the greatest example - but sometimes we need to use one value as an input to more than one intermediate value, and then operate on those intermediate values within the same scope - you can do that with S.

s2 : (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d

Spread the same arg with 2 maps over a two-arg function.

s3 : (b -> c -> d -> e) -> (a -> b) -> (a -> c) -> (a -> d) -> a -> e

Spread the same arg with 3 maps over a three-arg function.

s4 : (b -> c -> d -> e -> f) -> (a -> b) -> (a -> c) -> (a -> d) -> (a -> e) -> a -> f

Spread the same arg with 4 maps over a four-arg function.

s5 :
(b -> c -> d -> e -> f -> g)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> a
-> g

Spread the same arg with 5 maps over a five-arg function.

s6 :
(b -> c -> d -> e -> f -> g -> h)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> a
-> h

Spread the same arg with 6 maps over a six-arg function.

s7 :
(b -> c -> d -> e -> f -> g -> h -> i)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> (a -> h)
-> a
-> i

Spread the same arg with 7 maps over a seven-arg function.

s8 :
(b -> c -> d -> e -> f -> g -> h -> i -> j)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> (a -> h)
-> (a -> i)
-> a
-> j

Spread the same arg with 8 maps over an eight-arg function.

s9 :
(b -> c -> d -> e -> f -> g -> h -> i -> j -> k)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> (a -> h)
-> (a -> i)
-> (a -> j)
-> a
-> k

Spread the same arg with 9 maps over a nine-arg function.

s10 :
(b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> (a -> h)
-> (a -> i)
-> (a -> j)
-> (a -> k)
-> a
-> l

Spread the same arg with 10 maps over a ten-arg function.

s11 :
(b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m)
-> (a -> b)
-> (a -> c)
-> (a -> d)
-> (a -> e)
-> (a -> f)
-> (a -> g)
-> (a -> h)
-> (a -> i)
-> (a -> j)
-> (a -> k)
-> (a -> l)
-> a
-> m

Spread the same arg with 11 maps over an eleven-arg function.