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


 @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 adjusted(forTextChangeAt range: NSRange, text: String) -> ([Mention]) -> [Mention] {
    return { mentions in
        let remainingLengthOfMention = text.utf16.count - range.length
        return mentions.compactMap { mention in
            guard mention.range.location >= NSMaxRange(range) else { return mention }
            var adjustedMention = mention
            adjustedMention.range.location += remainingLengthOfMention
