Question: So I'm making a program which utilizes a Robot to copy and paste text. However, I've hit a wall when it comes to how to stop the Robot in the middle of its actions (I prefer using a button since the whole application is in a GUI). Right now I have it so that the Robot is created and starts when a different button is clicked, and it stops after a certain amount of messages. From what I understand you need to stop the thread it's on, but I'm not sure how to do that.

```
public void initSpam() throws AWTException
{

    Robot bot = new Robot();
    isRunning = true;

    int delayTime;
    if(isDefault)
        delayTime = DEFAULT;
    else
        delayTime = customTime;

    StringSelection selection = new StringSelection(spam);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(selection, selection);

    bot.delay(1250);

    for (int i = 0; i < buffer; i++) {
        bot.keyPress(KeyEvent.VK_CONTROL);
        bot.keyPress(KeyEvent.VK_V);
        bot.keyRelease(KeyEvent.VK_CONTROL);
        bot.keyRelease(KeyEvent.VK_V);
        bot.keyPress(KeyEvent.VK_ENTER);
        bot.keyRelease(KeyEvent.VK_ENTER);
        bot.delay(delayTime);
    }

}

```

The above is the method that's called when the other JButton is pressed. If anyone could guide me how to do this and explain how all of this threading works/how to work with it properly (assume I don't know much), I'd greatly appreciate it. 
Thank you!

Answer: 
I have no idea why you are trying to do this, so I may have missed the point entirely, but this is the closest I can get to it...

```
enum IntOrFunction {
    case Number(Int)
    case Function((Int -> Int))
    var function: (Int -> Int) {
        switch self {
        case .Function(let f):
            return f
        case .Number(let i):
            return { _ in return i }
        }
    }
}

func sum(params: Int...) -> IntOrFunction {
    if params.count == 1 {
        let a = params[0]
        return .Function({ b in a + b })
    } else {
        return .Number(params.reduce(0, combine: {$0 + $1}))
    }
}

let a = sum(1,2) // "Number(3)"
let b = sum(1) // "Function((Function))"
let c = b.function(3) // "4"

```
Currying is a method of translating function with multiple parameters into sequence of function. So no, there is no way to do that. Only thing you can do is to create "interface"

```
func sum(a: Int) -> (Int -> Int) {
    return { b in a + b }
}

func sum(a: Int, _ b: Int) -> Int {
    return sum(a)(b)
}

```