This library exposes an elm implementation of the birds from combinatory logic.
Each bird in the Aviary represents a function composition pattern and each bird is implemented, as far as is possible, using SKI combinator calculus under the hood.
To import all birds, add the following at the top of your file:
import Aviary.Birds exposing (..)You can also just import specific birds such as the Kestrel and Psi for example:
import Aviary.Birds exposing (kestrel, psi)Kestrel.
Returns the first argument provided, ignoring the second.
kestrel "hello" 2 --> "hello"
kestrel Nothing [ 1, 2, 3 ] --> Nothing
kestrel String.fromInt (Just 2) --> String.fromIntBluebird.
Composes the given functions with the final value.
The equivilent of the composition operator (<<) in Elm.
isEven : Int -> Bool
isEven n = modBy 2 n == 0
double : number -> number
double = ((*) 2)
bluebird not isEven 2 --> False
bluebird not isEven 1 --> True
bluebird String.fromInt double 4 --> "8"Cardinal, also known as "flip".
Takes a binary function and two further arguments which are then applied inversely.
multiplyList : List Int -> Int -> List Int
multiplyList items multiple =
List.map ((*) multiple) items
cardinal multiplyList 10 [1, 2, 3] --> [10, 20, 30]Useful in pipelines where the piped value is required to be the first argument to a function.
[1, 2, 3]
|> cardinal multiplyList 5
|> List.sum
--> 30Applicator.
Calls a given function with a given argument.
Sometimes referred to as "the reverse pipe operator".
The equivilent of the "pipe left" operator (<|) in Elm.
applicator String.fromInt 1 == "1"
applicator List.sum [ 1, 2, 3 ] == 6
applicator Result.fromMaybe Nothing == ErrPsi.
Transforms two inputs and combines the outputs.
Equivelent of the on operator in Haskell.
add : number -> number -> number
add = (+)
double : number -> number
double = ((*) 2)
psi add double 3 12 --> 30Becard.
Triple composition of a given value.
becard (\n -> n + 15) (\n -> n - 10) (\n -> n * 2) 50 --> 105
becard (Aviary.Birds.cardinal String.append "1") ((++) "2") String.fromInt 50 --> "2501"Blackbird.
blackbird String.toFloat String.append "3" ".14" --> Just 3.14
blackbird (modBy 2) (\x y -> x * y) 2 3 --> 0Bluebird prime.
bluebirdPrime (+) 1 Aviary.Birds.identity 2 --> 3
bluebirdPrime (++) [ 1, 2, 3 ] List.singleton 4 --> [1, 2, 3, 4]Bunting.
createUser : String -> Int -> Bool -> { name : String , age : Int , online : Bool }
createUser name age online = {
name = name ,
age = age ,
online = online
}
incrementUserAge : { name : String , age : Int , online : Bool } -> { name : String , age : Int , online : Bool }
incrementUserAge user =
{ user | age = user.age + 1 }
bunting List.sum (\x y z -> [x, y, z]) 1 2 3 --> 6
bunting incrementUserAge createUser "John" 36 True --> { name = "John", age = 37, online = True }Cardinal Prime.
cardinalPrime (+) ((-) 1) 5 10 --> -4
cardinalPrime List.append List.singleton [ 3, 2, 1 ] 4 --> [4, 3, 2, 1]Cardinal once removed.
Flips the third and fourth arguments when applied to the given ternary function.
cardinalStar Basics.clamp 100 200 150 --> 150
cardinalStar (\four six three -> four + six * three) 4 3 6 --> 22Cardinal twice removed.
Flips the fourth and fifth arguments when applied to the given quaternary function.
cardinalStarStar (\two four six three -> (two - four + six) * three) 2 4 3 6 --> 12Dickcissel.
dickcissel Basics.clamp 100 200 ((*) 2) 110 --> 200Dove.
dove (+) 5 Basics.identity 2 --> 7Dovekie.
dovekie (+) Basics.identity 2 ((*) 2) 11 --> 24Eagle.
eagle (+) 6 (*) 2 3 --> 12Bald eagle.
eaglebald (+) (-) 50 25 (*) 3 2 --> 31Finch.
finch 6 2 (-) --> -4
finch "Hi" 3 String.repeat --> "HiHiHi"Finch once removed.
Reverses the second, third and fourth arguments when applied to the given ternary function.
finchStar Basics.clamp 120 200 100 --> 120Finch twice removed.
Flips the third and fifth arguments when applied to the given quaternary function.
finchStar Basics.clamp 120 200 100 --> 120Goldfinch.
goldfinch (+) ((*) 2) 6 1 --> 13Hummingbird.
hummingbird (\x1 y x2 -> ( x1, x2, y )) 1 2 --> (1, 1, 2)Identity bird once removed.
identityStar (\n -> n - 1) 10 --> 9Identity bird twice removed
identityStarStar (\n m -> n - m) 10 4 --> 6Jay once removed.
jayStar Basics.identity 10 20 --> 10Jay Prime.
jayPrime (+) 10 20 40 --> 30Jay.
jay (+) 10 20 40 --> 70Kite.
Returns the second argument provided, ignoring the first.
kite "hello" 2 --> 2
kite Nothing [ 1, 2, 3 ] --> [ 1, 2, 3 ]
kite String.fromInt (Just 2) --> Just 2Owl.
owl (\f -> f 2 6) (+) 5 --> 13Quacky bird.
quacky 10 ((+) 2) ((*) 4) --> 48
quacky "John" String.toUpper (\name -> "My name is " ++ name) --> "My name is JOHN"Queer bird.
Reverse function composition.
queer ((+) 2) ((*) 4) 10 --> 48
queer String.toUpper (\name -> "My name is " ++ name) "John" --> "My name is JOHN"Quirky bird.
quirky ((+) 2) 10 ((*) 4) --> 48
quirky String.toUpper "John" (\name -> "My name is " ++ name) --> "My name is JOHN"Quixotic bird.
quixotic ((+) 2) 10 ((*) 4) --> 42
quixotic String.toUpper "John" (\name -> "My name is " ++ name) --> "MY NAME IS JOHN"Quizzical bird.
quizzical 10 ((+) 2) ((*) 4) --> 42
quizzical "John" String.toUpper (\name -> "My name is " ++ name) --> "MY NAME IS JOHN"Robin.
robin 10 (-) 12 --> 2
robin "second" (\a b -> a ++ " " ++ b) "first" --> "first second"Robin once removed.
robinStar Basics.clamp 10 100 200 --> 100
robinStar Basics.clamp 110 100 200 --> 110
robinStar Basics.clamp 220 100 200 --> 200Robin twice removed.
robinStarStar (\six nine ten four -> six - nine + ten * four) 6 4 9 10 --> 37Starling.
starling (+) ((*) 2) 10 --> 30
starling (-) (\v -> v * 7) 4 --> -24
starling (\user newAge -> { user | age = newAge }) (\user -> user.age + 1) { age = 35 } --> { age = 36 }Starling Prime.
starlingPrime (+) ((*) 2) ((-) 3) 5 --> 8Thrush.
Sometimes referred to as "the forward pipe operator".
The equivilent of the "pipe right" operator (|>) in Elm.
thrush 1 Basics.identity --> 1
thrush 20 ((+) 2) --> 22
thrush "Hello" (\v -> v ++ " world!") --> "Hello world!"Vireo.
vireo 1 2 (+) --> 3
vireo 3 "Hello" String.repeat --> "HelloHelloHello"Vireo once removed.
vireoStar (\two one three -> one + two - three) 1 2 3 --> 0Vireo twice removed.
vireoStarStar (\one four two three -> (one + two) - (three + four)) 1 2 3 4 --> -4Warbler.
Provides a given argument as both values to a given binary function.
warbler (+) 2 --> 4Warbler once removed.
warblerStar (\x y z -> [ x, y, z ]) 1 2 --> [1, 2, 2]Warbler twice removed.
warblerStarStar (\w x y z -> [ w, x, y, z ]) 1 2 3 --> [1, 2, 3, 3]
Identity, also known as "idiot".
Returns whatever it is given.