Skip to content

Commit 9eb1e59

Browse files
committed
add count to L
1 parent ec1be4a commit 9eb1e59

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

fastcore/foundation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def reduce(self, f, initial=None): return reduce(f, self) if initial is None els
189189
def sum(self): return self.reduce(operator.add, 0)
190190
def product(self): return self.reduce(operator.mul, 1)
191191
def setattrs(self, attr, val): [setattr(o,attr,val) for o in self]
192+
def count(self): return len(self)
192193

193194
# Cell
194195
add_docs(L,
@@ -220,7 +221,8 @@ def setattrs(self, attr, val): [setattr(o,attr,val) for o in self]
220221
reduce="Wrapper for `functools.reduce`",
221222
sum="Sum of the items",
222223
product="Product of the items",
223-
setattrs="Call `setattr` on all items"
224+
setattrs="Call `setattr` on all items",
225+
count="Count of the items"
224226
)
225227

226228
# Cell

nbs/02_foundation.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@
636636
" def reduce(self, f, initial=None): return reduce(f, self) if initial is None else reduce(f, self, initial)\n",
637637
" def sum(self): return self.reduce(operator.add, 0)\n",
638638
" def product(self): return self.reduce(operator.mul, 1)\n",
639-
" def setattrs(self, attr, val): [setattr(o,attr,val) for o in self]"
639+
" def setattrs(self, attr, val): [setattr(o,attr,val) for o in self]\n",
640+
" def count(self): return len(self)"
640641
]
641642
},
642643
{
@@ -675,7 +676,8 @@
675676
" reduce=\"Wrapper for `functools.reduce`\",\n",
676677
" sum=\"Sum of the items\",\n",
677678
" product=\"Product of the items\",\n",
678-
" setattrs=\"Call `setattr` on all items\"\n",
679+
" setattrs=\"Call `setattr` on all items\",\n",
680+
" count=\"Count of the items\"\n",
679681
" )"
680682
]
681683
},

0 commit comments

Comments
 (0)