Is it possible to define a function to prevent repeating lots of `case when` in transact sql? A meta post gives this code

Select top 500
(case 
    when lower(title) like '%open source%' then 0
    when lower(title) like '%recommend%'   then 1    
    when lower(title) like '%free%'        then 2
    when lower(title) like '%good%'        then 2
    when lower(title) like '%best%'        then 2
    when lower(title) like '%better%'      then 2
    when lower(title) like '%any%'         then 2
    when lower(title) like '%what%should%' then 3
    when lower(title) like '%which%should%'then 3
    when lower(title) like '%is there%'    then 3
    when lower(title) like '%looking for%' then 4
    else 5 end
), 
left(title,25) --as [Post Link]

,ROW_NUMBER() OVER (

  PARTITION BY(case 
      when lower(title) like '%open source%' then 0
      when lower(title) like '%recommend%'   then 1    
      when lower(title) like '%free%'        then 2
      when lower(title) like '%good%'        then 2
      when lower(title) like '%best%'        then 2
      when lower(title) like '%better%'      then 2
      when lower(title) like '%any%'         then 2
      when lower(title) like '%what%should%' then 3
      when lower(title) like '%which%should%'then 3
      when lower(title) like '%is there%'    then 3
      when lower(title) like '%looking for%' then 4
      else 5 end
  )
  ORDER BY (case 
      when lower(title) like '%open source%' then 0
      when lower(title) like '%recommend%'   then 1    
      when lower(title) like '%free%'        then 2
      when lower(title) like '%good%'        then 2
      when lower(title) like '%best%'        then 2
      when lower(title) like '%better%'      then 2
      when lower(title) like '%any%'         then 2
      when lower(title) like '%what%should%' then 3
      when lower(title) like '%which%should%'then 3
      when lower(title) like '%is there%'    then 3
      when lower(title) like '%looking for%' then 4
      else 5 end
)) AS Number

from posts

where (title like '%library%'
   or title like '%tool%'
   or title like '%book%'
   or title like '%tutorial%')
and closeddate is null
and deletiondate is null


In Python, Java, and lots of other language, I can define a function to prevent repeating lots of case when. Is there similar syntax in transact sql?
Use APPLY, like the examples I show in: http://blogs.lobsterpot.com.au/2011/12/13/a-t-sql-tip-working-calculations/

...then you can use it everywhere else as a regular column - just a calculated one. 

Select n.Num, left(title,25) --, etc
From posts 
Cross apply (select case 
  when lower(title) like '%open source%' then 0
  when lower(title) like '%recommend%'   then 1    
  when lower(title) like '%free%'        then 2
  when lower(title) like '%good%'        then 2
  when lower(title) like '%best%'        then 2
  when lower(title) like '%better%'      then 2
  when lower(title) like '%any%'         then 2
  when lower(title) like '%what%should%' then 3
  when lower(title) like '%which%should%'then 3
  when lower(title) like '%is there%'    then 3
  when lower(title) like '%looking for%' then 4
  else 5 end as Num) n
-- where ...
Order by n.num