def flat_map(&block)
      raise Erlang::ImproperListError if improper?
      return enum_for(:flat_map) unless block_given?
      return self if empty?
      out = tail = Erlang::Cons.allocate
      list = self
      until list.empty?
        head_list = Erlang::List.from_enum(yield(list.head))
        if head_list.empty?
          list = list.tail
        elsif list.tail.empty?
          tail.instance_variable_set(:@head, head_list.head)
          tail.instance_variable_set(:@tail, head_list.tail)
          tail.immutable!
          list = list.tail
        else
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@head, head_list.head)
          tail.instance_variable_set(:@tail, head_list.tail + new_node)
          tail.immutable!
          list = list.tail
          tail = new_node
        end
      end
      if not tail.immutable?
        tail.instance_variable_set(:@tail, Erlang::Nil)
        tail.immutable!
      end
      if out === tail and not out.tail.kind_of?(Erlang::List)
        return out.tail
      else
        return out
      end
    end
def flat_map(&block)
      raise Erlang::ImproperListError if improper?
      return enum_for(:flat_map) unless block_given?
      return self if empty?
      out = tail = Erlang::Cons.allocate
      list = self
      until list.empty?
        head_list = Erlang::List.from_enum(yield(list.head))
        if head_list.empty?
          list = list.tail
        elsif list.tail.empty?
          tail.instance_variable_set(:@head, head_list.head)
          tail.instance_variable_set(:@tail, head_list.tail)
          tail.immutable!
          list = list.tail
        else
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@head, head_list.head)
          tail.instance_variable_set(:@tail, head_list.tail + new_node)
          tail.immutable!
          list = list.tail
          tail = new_node
        end
      end
      if not tail.immutable?
        tail.instance_variable_set(:@tail, Erlang::Nil)
        tail.immutable!
      end
      if out === tail and not out.tail.kind_of?(Erlang::List)
        return out.tail
      else
        return out
      end
    end
Return a `List` which is realized by transforming each item into a `List`,
 and flattening the resulting lists.

 @example
   Erlang::List[1, 2, 3].flat_map { |x| Erlang::List[x, 100] }
   # => Erlang::List[1, 100, 2, 100, 3, 100]

 @return [List]