Last active
August 29, 2015 14:02
-
-
Save AlexanderNey/cce02e7d20a07353a58c to your computer and use it in GitHub Desktop.
lower and upper limiter operator in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LimitOperator.swift | |
// | |
// Created by Alexander Ney on 22/06/2014. | |
// Copyright (c) 2014 Alexander Ney. All rights reserved. | |
// | |
// Lower limit operator | |
operator infix |- {associativity right} | |
func |- <T : Comparable>(lowerLimit: T, value: T) -> T | |
{ | |
return value < lowerLimit ? lowerLimit : value; | |
} | |
// Upper limit operator | |
operator infix -| {associativity right} | |
func -| <T : Comparable>(value: T, upperLimit: T) -> T | |
{ | |
return value > upperLimit ? upperLimit : value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_Limiter Operators_
The will work like this
limitedNumber will be always in the limits including 0 ... 100
You can use the operators alone to just define a lower or upper limit