 
  @return [Mention]: A new mention array
  */
-internal func insert(_ newMentions: [(CreateMention, NSRange)]) -> (inout [Mention]) -> Void {
+internal func insert(_ newMentions: [(CreateMention, NSRange)]) -> ([Mention]) -> [Mention] {
     return { mentions in
-        mentions = mentions + newMentions.map { createMention, range in
+        mentions + newMentions.map { createMention, range in
             Mention(range: range, object: createMention)
         }
     }


 @return [Mention]: A new mention array
 */
internal func remove(_ mentionsToRemove: [Mention]) -> (inout [Mention]) -> Void {
    return { mentions in
        mentions = mentions.filter { !mentionsToRemove.contains($0)
        }
    }
}



 @return [Mention]: A new mention array
 */
internal func add(_ mention: CreateMention, spaceAfterMention: Bool, at range: NSRange) -> ([Mention]) -> [Mention] {
    return { mentions in
        let adjustedRange = range.adjustLength(for: mention.name)
        return mentions
            |> adjusted(forTextChangeAt: range, text: mention.mentionName(with: spaceAfterMention))
            |> insert([(mention, adjustedRange)])
    }
}
