Julia collections
By defining five functions on your citable collection, you can make them interoperate with dozens of generic Julia functions for working with collections of data.
What you need to define
Thes are the five functions you want to define:
using Base.Iterators
import Base: length
import Base: eltype
import Base: iterate
import Base: filter
import Base.Iterators: reverseIn many cases, you can implement these functions with a single line of code.
length: return the number of items in your collectioneltype: return the type of object your collection containsiterate: you need to implement two required methods, one for an initial state and taking a single parameter for the collection, a second with two parameters, giving the collection and some state information. If your collection is indexed (e.g., an Array type), your state information might simply be an index value.filter: you can usecollectto create an Array on your citable collection and filter the resulting Array.reverse: similarly, just collect the values of your collection and pass that toreverse
What you get
Some of the functions this gives you are:
functions returning iterators:
collectdropdropwhileenumerateflattenpartitionproductresttaketakewhilezip
functions returning other kinds of value:
accumulateallalluniqueanyargmaxargmincollectcountextremafirstinisemptymapreducefoldlfoldrmaximummapmapfoldlmapfoldrmapreduceminimumprodunique∌