module Stdlib.Function;

open import Stdlib.Data.Nat.Base;
open import Stdlib.Data.Product.Base;

infixr 9 ;
--- Function composition.
 : {A : Type}{B : Type}{C : Type}(BC)(AB)AC;
 f g x := f (g x);

--- Always returns the first argument.
const : {A : Type}{B : Type}ABA;
const a _ := a;

--- The identity function.
id : {A : Type}AA;
id a := a;

--- Swaps the order of the arguments of the given function.
flip : {A : Type}{B : Type}{C : Type}(ABC)BAC;
flip f b a := f a b;

infixr 0 $;
--- Application operator with right associativity. Usually used as a syntactical
--- facility.
$ : {A : Type}{B : Type}(AB)AB;
$ f x := f x;

--- Applies a function n times.
iterate : {A : Type} -> Nat -> (A -> A) -> A -> A;
iterate zero _ a := a;
iterate (suc n) f a := iterate n f (f a);

infixl 0 on;
on : {A : Type}{B : Type}{C : Type}(BBC)(AB)AAC;
on f g a b := f (g a) (g b);

infixl 1 >>>;
builtin seq
>>> : {A B : Type}ABB;
>>> x y := y;
Last modified on 2023-05-08 11:40 UTC