// MapCons adds (conses) a new key/value pair onto an iseq.PMap // A MapEntry adds its key/value. // A PVector uses v[2*i] v[2*i+1] as key/value pairs // Otherwise, we need a sequence of iseq.MapEntry values // Assumes its argument is one of the above; else panics func MapCons(m iseq.PMap, o interface{}) iseq.PMap { if me, ok := o.(iseq.MapEntry); ok { return m.AssocM(me.Key(), me.Val()) } if v, ok := o.(iseq.PVector); ok { if v.Count() != 2 { panic("Vector arg to map cons must be a pair") } return m.AssocM(v.Nth(0), v.Nth(1)) } ret := m for s := ConvertToSeq(o); s != nil; s = s.Next() { me := s.First().(iseq.MapEntry) ret = ret.AssocM(me.Key(), me.Val()) } return ret }