shithub: mc

ref: f995117702dd77f832b2a70ce94c4f5c9848efd4
dir: /lib/std/extremum.myr/

View raw version
pkg std =
	generic min	: (a : @a, b : @a -> @a)		:: numeric @a
	generic max	: (a : @a, b : @a -> @a)		:: numeric @a
	generic clamp	: (a : @a, min : @a, max : @a -> @a)	:: numeric @a
	generic abs	: (a : @a -> @a)			:: numeric @a
;;

generic min = {a, b
	if a < b
		-> a
	else
		-> b
	;;
}

generic max = {a, b
	if a > b
		-> a
	else
		-> b
	;;
}

generic clamp = {a, min, max
	if a < min
		-> min
	elif a > max
		-> max
	else
		-> a
	;;
}

generic abs = {a : @a :: numeric @a
	if a < (0 : @a)
		-> -a
	else
		-> a
	;;
}