| 664 | } |
| 665 | |
| 666 | static int countFrom(Object o){ |
| 667 | if(o == null) |
| 668 | return 0; |
| 669 | else if(o instanceof IPersistentCollection) { |
| 670 | ISeq s = seq(o); |
| 671 | o = null; |
| 672 | int i = 0; |
| 673 | for(; s != null; s = s.next()) { |
| 674 | if(s instanceof Counted) |
| 675 | return i + s.count(); |
| 676 | i++; |
| 677 | } |
| 678 | return i; |
| 679 | } |
| 680 | else if(o instanceof CharSequence) |
| 681 | return ((CharSequence) o).length(); |
| 682 | else if(o instanceof Collection) |
| 683 | return ((Collection) o).size(); |
| 684 | else if(o instanceof Map) |
| 685 | return ((Map) o).size(); |
| 686 | else if (o instanceof Map.Entry) |
| 687 | return 2; |
| 688 | else if(o.getClass().isArray()) |
| 689 | return Array.getLength(o); |
| 690 | |
| 691 | throw new UnsupportedOperationException("count not supported on this type: " + o.getClass().getSimpleName()); |
| 692 | } |
| 693 | |
| 694 | static public IPersistentCollection conj(IPersistentCollection coll, Object x){ |
| 695 | if(coll == null) |