ThinkThen

Beatles Bench pages
Scripts
What Jev knows
Tune your bar
Beatles Bench · The ten functions

rank sorts by your criteria.

The talk's slide: rank sorts by your criteria.
Open the slide at full size.

rank is a sort that reads. It asks one yes or no question of each record and sorts the records by the probability of yes.

Run it

All twelve songs, likeliest hit first.
is_a_song="The text is the title of a song by the Beatles."
a_big_hit="It is one of the Beatles' biggest hits."
question="$is_a_song $a_big_hit"

cat <<'EOF' |
Something
Hey Jude
Blackbird
Help!
Octopus's Garden
She Loves You
Piggies
Yesterday
Penny Lane
Her Majesty
Can't Buy Me Love
Good Night
EOF
thinkthen rank "$question" \
  --batch 1 \
  --replay recording
Output
Hey Jude
Help!
She Loves You
Yesterday
Can't Buy Me Love
Penny Lane
Something
Blackbird
Piggies
Octopus's Garden
Good Night
Her Majesty
exit 0: the run finished

Set the cut

--top 5 keeps the first five.
is_a_song="The text is the title of a song by the Beatles."
a_big_hit="It is one of the Beatles' biggest hits."
question="$is_a_song $a_big_hit"

cat <<'EOF' |
Something
Hey Jude
Blackbird
Help!
Octopus's Garden
She Loves You
Piggies
Yesterday
Penny Lane
Her Majesty
Can't Buy Me Love
Good Night
EOF
thinkthen rank "$question" \
  --batch 1 \
  --top 5 \
  --replay recording
Output
Hey Jude
Help!
She Loves You
Yesterday
Can't Buy Me Love
exit 0: the run finished

The lesson

Both runs give the same order. --top 5 prints the first five and asks nothing new.

rank drops nothing. You choose where the list ends.