Skip to main content
deleted 22 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Get suffixes

Use scanr(:)[] to get the suffixes of a list:

λ scanr(:)[] "abc"
["abc","bc","c",""]

This is much shorter than tails after import Data.List. You can do prefixes with scanl(\s cscanr(\_->s++[c]>init)[]=<<id (found by Ørjan Johansen).

λ scanl(\s cscanr(\_->s++[c]>init)[]=<<id $ "abc"
["","a","ab","abc"]

This is longer but still beats the import. Pointfree is the same length:saves a byte over

scanl((.pure).(++)\s c->s++[c])[]

Get suffixes

Use scanr(:)[] to get the suffixes of a list:

λ scanr(:)[] "abc"
["abc","bc","c",""]

This is much shorter than tails after import Data.List. You can do prefixes with scanl(\s c->s++[c])[].

λ scanl(\s c->s++[c])[] "abc"
["","a","ab","abc"]

This is longer but still beats the import. Pointfree is the same length:

scanl((.pure).(++))[]

Get suffixes

Use scanr(:)[] to get the suffixes of a list:

λ scanr(:)[] "abc"
["abc","bc","c",""]

This is much shorter than tails after import Data.List. You can do prefixes with scanr(\_->init)=<<id (found by Ørjan Johansen).

λ  scanr(\_->init)=<<id $ "abc"
["","a","ab","abc"]

This saves a byte over

scanl(\s c->s++[c])[]
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Get suffixes

Use scanr(:)[] to get the suffixes of a list:

λ scanr(:)[] "abc"
["abc","bc","c",""]

This is much shorter than tails after import Data.List. You can do prefixes with scanl(\s c->s++[c])[].

λ scanl(\s c->s++[c])[] "abc"
["","a","ab","abc"]

This is longer but still beats the import. Pointfree is the same length:

scanl((.pure).(++))[]