Assuming you mean that you have a list of Strings, then this should work:
customSorter = {
[ 'daily', 'monthly', 'weekly' ].indexOf( it )
}
assert [ 'daily', 'monthly', 'weekly' ].sort( customSorter ) == [ 'daily', 'monthly', 'weekly' ]
assert [ 'monthly', 'weekly', 'daily' ].sort( customSorter ) == [ 'daily', 'monthly', 'weekly' ]
assert [ 'weekly', 'daily' ].sort( customSorter ) == [ 'daily', 'weekly' ]
Or you could do this (to avoid repeatedly creating a List)
customSorter = { a, b, order=['daily','monthly','weekly'] ->
order.indexOf( a ) <=> order.indexOf( b )
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…